[英]c# UWP - Tiles OnNavigatedTo doesn't keep variables in MainPage
I've just integrated the Tile creation within my application. 我刚刚在应用程序中集成了Tile创建。
The Tiles are created just fine. 创建图块就好了。 I set a string parameter to use when the app is launched from the Tile.
我设置了从Tile启动应用程序时要使用的字符串参数。
in my Class.xaml.cs : 在我的Class.xaml.cs中 :
string tileActivationArguments = "test_params";
SecondaryTile s = new SecondaryTile(name_clean,
name,
name,
tileActivationArguments,
TileOptions.ShowNameOnLogo,
logo);
s.DisplayName = name;
s.ForegroundText = ForegroundText.Dark;
bool isPinned = await s.RequestCreateForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);
And it's pinned with succes. 而且它被成功钉住了。
But when I click on the Tile from the startup menu, I arrive on MainPage.OnNavigatedTo
and here, the params are existing, and I set them on a local variable. 但是,当我从启动菜单中单击Tile时,我到达
MainPage.OnNavigatedTo
,在这里,这些参数已经存在,并且将它们设置在局部变量上。
MainPage.xaml.cs MainPage.xaml.cs
private string params;
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var parametters = e.Parameter as string;
if (parametters != null && parametters != "")
{
params = parametters ; // WORKS: here params has the good parameter string
....
}
}
then, it goes into MainPage() 然后,它进入MainPage()
public MainPage()
{
this.InitializeComponent();
// here the params seems to be reset
Debug.WriteLine(params); // Exception
// params == null
...
}
Any Ideas ? 有任何想法吗 ?
构造函数始终在OnNavigatedTo
之前OnNavigatedTo
调用,此时params
仍为null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.