Ich versuche, eine Windows Phone 8.1 Silverlight
App UWP
zu migrieren. Ich habe einen Fehler bekommen Main Application UI
.Universal-Windows-Plattform (UWP) gleichwertig UI Hauptanwendung zu bekommen
Dies ist das Fenster Windows Phone 8.1 Silverlight
Code:
Storage storage = ((App.Current.RootVisual as PhoneApplicationFrame).DataContext as Storage);
Dies ist, was ich für die UWP
Version getan haben:
Storage storage = ((Window.Current.Content as Frame).DataContext as Storage);
ich eine NullPointerException
bekommen. Irgendwelche Ideen?
Vielen Dank im Voraus.
EDIT
Das ist mein XAML:
<Page
x:Class="windows_phone.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="20"
Foreground="#FF000000">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0">
<WebView
x:Name="webView"
Margin="0,0,0,0"
Grid.Row="1"
/>
</Grid>
</Grid>
Das ist meine Klasse Store, um die letzte Uri zu speichern:
namespace windows
{
public class Storage
{
#region Properties
private Uri _lastUri = null;
public Uri lastUri
{
get {return _lastUri;}
set
{
_lastUri = value;
}
}
#endregion
}
}
ZWEITE EDIT
-Code, wo ich Shop-Klasse verwenden:
public sealed partial class MainPage : Page
{
private Storage storage = null;
....
protected override void OnNavigatedTo(NavigationEventArgs e)
{
storage = (((Window.Current.Content as Frame).Content as Page).DataContext as Storage);
if (Storage.lastUri != null) webView.Navigate(Storage.lastUri);
base.OnNavigatedTo(e);
}
void webView_LoadCompleted(object sender, NavigationEventArgs e)
{
if (webView.Source.ToString().Contains("login"))
{
string id = LoadUserIdFromIsolatedStorage();
String[] data = new String[1];
data[0] = id;
if (id != null)
webView.InvokeScript("WinHelp", data);
}
progressIndicator.Visibility = Visibility.Collapsed;
Storage.lastUri = e.Uri;
}
Wenn ich Sie richtig verstehe, möchten Sie den DataContext des aktiven Rahmens erhalten? –
Ja, genau das. – IrApp
Wird dies von einem Code hinter einer Datei oder einer separaten Klasse abgerufen? –