C# 如何在创建辅助磁贴时设置导航URI?(Windows Phone 8.1-通用)
假设我有一个特定的页面,SecondaryTile.xaml。从这个页面,我将一个辅助磁贴固定到startscreen。现在,如果我点击辅助磁贴,我希望它打开SecondaryTile.xaml 在WP8.0中,这可以通过设置Shell.Create的URI来实现。例如:C# 如何在创建辅助磁贴时设置导航URI?(Windows Phone 8.1-通用),c#,live-tile,win-universal-app,C#,Live Tile,Win Universal App,假设我有一个特定的页面,SecondaryTile.xaml。从这个页面,我将一个辅助磁贴固定到startscreen。现在,如果我点击辅助磁贴,我希望它打开SecondaryTile.xaml 在WP8.0中,这可以通过设置Shell.Create的URI来实现。例如: ShellTile.Create(new Uri("/SecondaryTile.xaml?Parameter=FromTile", UriKind.Relative), NewTileData); } 但W
ShellTile.Create(new Uri("/SecondaryTile.xaml?Parameter=FromTile", UriKind.Relative), NewTileData);
}
但WinRT似乎不再支持这种功能
我看到一个使用参数启动的示例,它在Mainpage.xaml.cs上的OnNavigatedTo中获取参数,但由于新的应用程序行为,应用程序被挂起,因此OnNavigatedTo并不总是触发
希望有人能帮忙
亲切问候,,
Niels这不应该作为应用程序逻辑来完成吗 检查应用程序代码隐藏的OnLaunched方法中的LaunchActivatedEventArgs参数:
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
ApplicationData.Current.LocalSettings.Values[Constants.APP_PARAMETERS] = args.Arguments;
// Do not repeat app initialization when already running, just ensure that
// the window is active
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
Window.Current.Activate();
await ViewManager.Instance.LaunchView();
return;
}
考虑实施某种类型的ViewManager来管理启动视图:
public class ViewManager
{
#region Singleton
private ViewManager()
{
}
static ViewManager _viewManager = null;
public static ViewManager Instance
{
get
{
if (_viewManager == null)
{
_viewManager = new ViewManager();
}
return _viewManager;
}
}
#endregion
public async Task LaunchView()
{
bool displaySubheader = false;
var displayBackbutton = false;
var arguments = ApplicationData.Current.LocalSettings.Values[Constants.APP_PARAMETERS] as string;
var argumentsExist = !string.IsNullOrEmpty(arguments);
if (!argumentsExist)
{
await UIServices.Instance.Load(typeof(HomePage), null, displaySubheader, displayBackbutton);
}
else
{
displaySubheader = true;
displayBackbutton = false;
await UIServices.Instance.Load(typeof(GroupPage), arguments, displaySubheader, displayBackbutton);
var groupId = new Guid(arguments);
await ReadPost(groupId);
}
}
。
.
以下是我如何创建辅助分幅:
SecondaryTile secondaryTile =
new SecondaryTile(group.GroupId.ToString(),
group.Name,
group.Name,
group.GroupId.ToString(),
TileOptions.ShowNameOnWideLogo,
new Uri("ms-appx:///Assets/Logo.png"),
new Uri("ms-appx:///Assets/WideLogo.scale-100.png"));
var successful = await secondaryTile.RequestCreateAsync();
您无法从OnNavigatedTo事件直接导航到其他页面。但是,您可以将导航添加为UI线程上的排队事件 在OnNavigatedToEventHandler中,检查以下内容您的测试可能需要更复杂一些,因为在本例中并不是所有的事件都被考虑在内,例如e参数为null
if (e.Parameter.ToString().Contains("something_from_secondary_tile_arguments") && (e.NavigationMode == NavigationMode.New))
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Current.Frame.Navigate(typeof(Transactions), "data_for_your_sub_page"); });
}
此外,在创建SecondaryTile时,还需要指定Arguments属性
更多信息请点击此处: