【问题标题】:How to set the navigation URI while creating a secondary tile? (Windows Phone 8.1 - Universal)如何在创建辅助磁贴时设置导航 URI? (Windows Phone 8.1 - 通用)
【发布时间】:2014-09-07 13:11:17
【问题描述】:

假设我有一个特定页面,SecondaryTile.xaml。在此页面中,我将辅助磁贴固定到开始屏幕。现在,如果我点击辅助磁贴,我希望它打开 SecondaryTile.xaml。

在 WP8.0 中,这可以通过设置 Shell.Create 的 URI 来实现。例如:

ShellTile.Create(new Uri("/SecondaryTile.xaml?Parameter=FromTile", UriKind.Relative), NewTileData);
        }

但 WinRT 似乎不再支持此功能。

我看到了一个使用参数启动的示例(它在 Mainpage.xaml.cs 上的 OnNavigatedTo 中获取参数),但由于新的应用行为,应用被暂停,因此 OnNavigatedTo 并不总是触发。

希望有人能提供帮助。

亲切的问候, 尼尔斯

【问题讨论】:

    标签: c# live-tile win-universal-app


    【解决方案1】:

    这不应该作为应用程序逻辑来完成吗?

    检查应用代码隐藏的 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();
    

    【讨论】:

      【解决方案2】:

      您无法从 OnNavigatedTo 事件直接导航到另一个页面。但是,您可以将导航添加为 UI 线程上的排队事件。

      在您的 OnNavigatedTo 事件处理程序中,检查以下内容(您的测试可能需要更复杂一些,因为在此示例中并未考虑所有可能性,例如 e.Parameters beeing 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 属性。

      更多信息在这里:Not able to navigate to pages on Windows Metro App using c#

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多