MVVM模式应用 之在ViewModel中使用NavigationService

时间:2023-03-09 15:05:17
MVVM模式应用 之在ViewModel中使用NavigationService

在ViewModel.cs页面中是不能使用NavigationService,那该怎么实现跳转呢?

其实在ViewModel中实现页面的跳转也很简单,下面的代码:

using Microsoft.Phone.Controls;
public void NavigateToAddUniversity()
        {
            var root = App.Current.RootVisual as PhoneApplicationFrame;
            try
            {
                root.Navigate(new Uri("/View/AddUniversity.xaml", UriKind.Relative));
            }catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("错误是:"+ex.ToString());
            }
        }

这样就可以实现跳转了。

参考链接:http://blog.csdn.net/antsnm/article/details/7202382