簡體   English   中英

輔助磁貼導航Windows Phone 8

[英]Secondary Tile Navigation Windows Phone 8

從輔助磁貼導航到我的應用程序時出現問題。 磁貼已創建並具有導航uri。 現在我有一個問題:

在“ navigateTo”上,我測試了特定字符串的導航上下文。 如果字符串中有數字,我稱這個數字。 我遇到的第一個問題是,當我導航至應用程序內的另一個頁面(首先單擊輔助磁貼后),然后返回主頁面時,它也嘗試調用該號碼,因為navigationcontext與我單擊該主題時相同次要磁貼。 如果我在第一次單擊輔助圖塊后清除了導航上下文,則導航將起作用。 但是,如果我暫停應用程序,然后再次單擊輔助磁貼,則導航上下文為空,因此不會調用任何數字。

創建瓷磚

IconicTileData tileData = new IconicTileData
{
    Title = App.MainViewModel.SelectedPOI.Name,
    SmallIconImage = new Uri("/Assets/Images/feature.phone.png", UriKind.Relative),
    WideContent1 = App.MainViewModel.SelectedPOI.Name,
    WideContent2 = App.MainViewModel.SelectedPOI.Telefonnumber,
    WideContent3 = App.MainViewModel.SelectedPOI.Street
};
if (App.MainViewModel.SelectedPOI.Id == -1)
    tileData.BackgroundColor = Helper.GetColorFromHexString("#E46D1D");
else
    tileData.BackgroundColor = Helper.GetColorFromHexString("#4FAE32");

string SecondaryTileUriSource = String.Format("Source={0}&ID={1}", TILESTATUS, App.MainViewModel.SelectedPOI.Id);

//check if tile exist
ShellTile tile = Helper.FindTile(SecondaryTileUriSource);
if (tile == null)
{
    // having a unique NavigationUri is necessary for distinguishing this tile
    string tileUri = string.Concat("/MainPage.xaml?", SecondaryTileUriSource);
    ShellTile.Create(new Uri(tileUri, UriKind.Relative), tileData, true);
}

OnNavigateTo-主頁

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    string status = String.Empty;
    if (NavigationContext.QueryString.TryGetValue("Source", out status))
    {
        MainPivot.SelectedItem = AlarmPivotItem;
        //App.MainViewModel.StartAlarm();
        //or
        //get the number from source/status...
        App.MainViewModel.CallNumber(12345);
        //NavigationContext.QueryString.Clear();
    }
}

有沒有人舉過一個例子,例如,從輔助磁貼中調用了一個數字,而應用程序內部可能至少有2頁? 還有其他建議可以解決問題嗎?

謝謝

無需清除導航上下文,您可以使用NavigationMode屬性來了解它是對頁面的新導航(例如,形成輔助圖塊)還是用戶是否從另一個頁面返回:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
    {
        if (NavigationContext.QueryString.TryGetValue("Source", out status))
        {
            MainPivot.SelectedItem = AlarmPivotItem;
            //App.MainViewModel.StartAlarm();
            //or
            //get the number from source/status...
            App.MainViewModel.CallNumber(12345);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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