sealed partial class App : Template10.Common.BootStrapper
{
...
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
if ((args as LaunchActivatedEventArgs).Arguments == "GoToSecondPage")
await NavigationService.NavigateAsync(typeof(Views.SecondPage));
else if ((args as LaunchActivatedEventArgs).Arguments == "GoToThirdPage")
await NavigationService.NavigateAsync(typeof(Views.ThirdPage));
else
await NavigationService.NavigateAsync(typeof(Views.MainPage));
await ConfigureJumpList();
}
...
private async Task ConfigureJumpList()
{
JumpList jumpList = await JumpList.LoadCurrentAsync();
jumpList.Items.Clear();
jumpList.Items.Add(JumpListItem.CreateWithArguments("GoToSecondPage", "Go directly to the 2nd page"));
jumpList.Items.Add(JumpListItem.CreateWithArguments("GoToThirdPage", "Visit 3rd page"));
await jumpList.SaveAsync();
}
}
如果您想在 JumpListItem 中显示自定义图标,那么您需要做的就是替换这行代码
jumpList.Items.Add(JumpListItem.CreateWithArguments("GoToSecondPage", "Go directly to the 2nd page"));
有以下几行
var secondPageItem = JumpListItem.CreateWithArguments("GoToSecondPage", "Go directly to the 2nd page");
secondPageItem.Logo = new Uri("ms-appx:///Icons/Page2Icon.png");
jumpList.Items.Add(secondPageItem);
1 回答
假设你有一个名为
SecondPage
和ThirdPage
的页面,你想直接从JumpList
导航 .首先,您需要将相应的项添加到
JumpList
本身:执行此操作的标准位置在应用程序的
OnLaunched
方法中(App.xaml.cs
文件) . 有关用户单击的JumpListItem
的信息也作为参数传递给此方法,因此您可能希望将页面导航逻辑放入OnLaunched
方法中,并使其看起来像:因此,您的
App.xaml.cs
文件将如下所示:如果您使用模板10,那么一切都是相同的,除了一些次要的代码更改以及您编辑
OnStartAsync()
而不是OnLaunched()
方法的事实,因此App.xaml.cs
文件中的最终结果应如下所示:如果您想在
JumpListItem
中显示自定义图标,那么您需要做的就是替换这行代码有以下几行
其中
"ms-appx:///Icons/Page2Icon.png"
是图标的路径(在此示例中为项目的Icons文件夹中的Page2Icon.png文件) .