[英]c# UWP - Tiles OnNavigatedTo doesn't keep variables in MainPage
我刚刚在应用程序中集成了Tile创建。
创建图块就好了。 我设置了从Tile启动应用程序时要使用的字符串参数。
在我的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);
而且它被成功钉住了。
但是,当我从启动菜单中单击Tile时,我到达MainPage.OnNavigatedTo
,在这里,这些参数已经存在,并且将它们设置在局部变量上。
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
....
}
}
然后,它进入MainPage()
public MainPage()
{
this.InitializeComponent();
// here the params seems to be reset
Debug.WriteLine(params); // Exception
// params == null
...
}
有任何想法吗 ?
构造函数始终在OnNavigatedTo
之前OnNavigatedTo
调用,此时params
仍为null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.