簡體   English   中英

C#UWP-Tiles OnNavigatedTo在MainPage中不保留變量

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM