2013-05-29 48 views
3

我目前正在使用C#開發Windows應用商店應用程序。在我的應用程序中,我使用次級拼貼選項,使用以下代碼將我的一個特徵固定到開始屏幕。如何從Windows Store應用程序中的SecondaryTile導航到特定頁面?

if (SecondaryTile.Exists(TileId)) 
      { 
       var secondaryTile = new SecondaryTile(TileId); 
       await econdaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Above); 
      } 
      else 
      { 
       var logo = new Uri("ms-appx:///Assets/A.png", UriKind.RelativeOrAbsolute); 

       var secondaryTile = new SecondaryTile 
       { 
        Logo = logo, 
        TileId = TileId, 
        ShortName = "AAAA", 
        Arguments = TileId + DateTime.Now.ToLocalTime(), 
        DisplayName = "AAAAAAA BBBBBBB", 
        TileOptions = TileOptions.ShowNameOnLogo, 
        ForegroundText = ForegroundText.Dark 
       }; 

       await secondaryTile.RequestCreateForSelectionAsync(GetElementRect(sender as FrameworkElement), Placement.Above); 
      } 

因此它現在將SecondaryTile託管到Start屏幕。但是對於我的要求,無論用戶何時點擊開始屏幕上的SecondaryTile,它都應該導航到頁面「A」。我們可以在Windows應用商店應用中實現嗎

回答

4

是的,但您應該使用另一個SecondaryTile構造函數來傳遞一些參數以及圖塊ID。您不需要使用其他構造函數,因爲您只能使用Tile ID來決定啓動時您的應用必須執行的頁面,但我認爲使用參數發送頁面名稱或標識更好。

public SecondaryTile(
    string tileId, 
    string shortName, 
    string displayName, 
    string arguments, 
    TileOptions tileOptions, 
    Uri logoReference 
) 

Documentation says that arguments is:

應用程式定義的字符串有意義到調用應用程序。這個 參數字符串會在次應用程序圖塊中激活 時傳遞迴應用程序。它將在2048個字符後截斷。 可以設置或檢索通過Arguments屬性

所以,你可以通過標識,當用戶點擊二級瓷磚必須啓動,然後用它在你的App.xaml.cs頁面的字符串OnLaunched方法,當應用程序被激活:

async protected override void OnLaunched(LaunchActivatedEventArgs args) 
{ 
    var tile_id = args.TileId; 
    var tile_arguments = args.Arguments; 
    // Depending on tile_id and tile_arguments navigate to the page you want 
} 

請注意,您也應該知道的args.PreviousExecutionStateOnLaunched方法。您的OnLaunched方法不能只是這樣。

+0

感謝您的幫助.. :) –

+2

我今天幫了你,明天你會幫我的!這是stackoverflow :) – letiagoalves

相關問題