c# - 如何从 Windows 应用商店应用程序中的 SecondaryTile 导航到特定页面?

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

我目前正在使用 C# 开发 Windows 应用商店应用程序。在我的应用程序中,我使用辅助平铺选项使用以下代码将我的功能之一固定到“开始屏幕”。

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 应用商店应用中实现这一点?

最佳答案

是的,但您应该使用另一个 SecondaryTile 构造函数来传递一些参数以及图 block ID。您不需要使用其他构造函数,因为您可以仅使用 Tile ID 来决定您的应用在启动时必须转到哪个页面,但我认为最好使用参数来发送页面名称或标识。

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

Documentation says that arguments is:

An app-defined string meaningful to the calling application. This argument string is passed back to the app when the app is activated from the secondary tile. It will be truncated after 2048 characters. Can be set or retrieved through the Arguments property

因此,您可以传递一个字符串来标识当用户单击辅助磁贴时必须启动的页面,然后在您的 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 方法不能只是这个。

关于c# - 如何从 Windows 应用商店应用程序中的 SecondaryTile 导航到特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16815302/

相关文章:

c# - 获取 NegotiatedContentResult 的 StatusCode

c# - 给定一组点查找区域

c# - Windows Phone 8 - 创建 "Fade-in and slide-in"动画

wpf - 在Visual Studio 2010中调试和修复ObjectDisposedException

c++ - 桌面版和 Metro Windows 8 的通用 UI

javascript - TRACKER : error TRK0005: Failed to locate: "CL.exe". 系统找不到指定的文件

c++ - XAudio2 延迟声音 - 播放多个声音时

c# - 将 XAML 窗口类型传递给函数

c# - WPF复选框双向绑定(bind)不起作用

c# - 动画 TopMargin 的 ObjectAnimator 代理找不到设置/ getter