【问题标题】:How to Navigate to running screen if app is accessed in windows phone?如果在 Windows Phone 中访问应用程序,如何导航到运行屏幕?
【发布时间】:2013-06-21 14:49:51
【问题描述】:

我正在尝试开发位置跟踪。在这个应用程序中,第一个用户打开主屏幕。然后他选择运行导航到第二个屏幕的应用程序。然后它也可以在后台运行。现在,如果用户打开应用程序,他应该直接转到第二个屏幕,而不是再次转到第一个屏幕。如何?任何建议,请发表。
//代码

 private void Timer_Tick(object sender, EventArgs e)
        {  TimeSpan runTime = TimeSpan.FromMilliseconds(System.Environment.TickCount - _startTime);
    timeLabel.Text = runTime.ToString(@"hh\:mm\:ss");
        }

【问题讨论】:

  • 应用程序是完全退出,还是刚刚暂停?
  • 如果应用程序在没有停止的情况下退出,它将在后台运行。

标签: .net windows-phone-7 xaml c#-4.0 windows-phone-8


【解决方案1】:

最简单的方法(我认为)是,在加载第一个屏幕时,重定向到第二个屏幕,然后从后台删除页面。

在第一个屏幕中:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    NavigationService.Navigate(new Uri("/SecondScreen.xaml", UriKind.Relative));
}

在第二个屏幕中:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    NavigationService.RemoveBackEntry();
}

另一种方法是使用自定义 URI 映射器在调用第一个屏幕时显示第二个屏幕。它有点复杂,但您可以避免现在无用的导航到第一个屏幕。此代码应该只在导航之前调用一次,最好是在 App.xaml.cs 中的应用程序初始化期间:

var mapper = new UriMapper();

int random = new Random().Next(0, 3);

mapper.UriMappings.Add(new UriMapping
{
    Uri = new Uri("/FirstScreen.xaml", UriKind.Relative),
    MappedUri = new Uri("/SecondScreen.xaml", UriKind.Relative)
});

Application.Current.RootFrame.UriMapper = mapper;

【讨论】:

  • 嗨 Kookiz,很抱歉你没有得到我的问题。在第二个屏幕中,计时器正在运行。因此,如果计时器在后台运行,它应该导航到第二个屏幕,否则它应该从第一个屏幕开始。请检查我重新发布的上面的代码。谢谢你兄弟。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-03
  • 1970-01-01
  • 2015-07-07
  • 2014-09-02
相关资源
最近更新 更多