【问题标题】:How to navigate to the particular page from SecondaryTile in Windows Store apps?如何从 Windows Store 应用程序中的 SecondaryTile 导航到特定页面?
【发布时间】:2013-05-29 13:31:30
【问题描述】:

我目前正在使用 C# 开发 Windows Store 应用程序。在我的应用程序中,我使用 Secondary Tile 选项使用以下代码将我的一项功能固定到开始屏幕。

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 托管到“开始”屏幕。但是对于我的要求,每当用户从“开始”屏幕单击 SecondaryTile 时,它​​应该导航到页面“A”。我们可以在 Windows 应用商店应用中实现这一点吗?

【问题讨论】:

    标签: c# xaml windows-8 windows-store-apps


    【解决方案1】:

    是的,但您应该使用另一个 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
    }
    

    请注意,您还应该注意 OnLaunched 方法中的 args.PreviousExecutionState。你的OnLaunched 方法不能只有这个。

    【讨论】:

    • 我今天帮了你,你明天帮我!这是堆栈溢出 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    相关资源
    最近更新 更多