如何使用PRISM从wpf mvvm中的一个页面导航到另一个xaml页面 [英] How To navigate from one page to another xaml page in wpf mvvm using PRISM

查看:773
本文介绍了如何使用PRISM从wpf mvvm中的一个页面导航到另一个xaml页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,任何人都可以给出任何例子

Hi can anyone give any example

推荐答案

在包含框架的视图的viewmodel中,创建一个属性来保持页面的导航,

Hi, In your viewmodel of the view that contains the frame, create a property to keep the page to navigate like,
private Page _PageToNavigate;
public Page PageToNavigate
{
   get { return _PageToNavigate; }
   set { _PageToNavigate = value; OnPropertyChanged("PageToNavigate"); }
}



并将此属性绑定到视图中的Frame的Content属性,例如,


And bind this property to Frame's Content property in your view like,

<frame x:name="Browser" content="{Binding PageToNavigate}" xmlns:x="#unknown" />



现在,您只需要指定要导航到 PageToNavigate 属性。它定义了 OnPropertyChanged ,因此无论在何处使用此属性,都会使用当前指定的值(即页面)更新它。


Now, you just need to assign the page which you want to navigate to the PageToNavigate property. It has OnPropertyChanged defined, so wherever this property is used, everywhere it gets updated with the currently assigned value (i.e., page).


在Xaml中:





导航

C#:



私人void continueButton_Click(object sender,RoutedEventArgs e)

{

this.NavigationService.GoForward();

//或

this.NavigationService.Navigate(Second.xaml)

}

in Mvvm:







In Xaml:


Navigate
C#:

private void continueButton_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.GoForward();
//or
this.NavigationService.Navigate("Second.xaml")
}
in Mvvm:



In Views (We have a Commands.cs file that contains all of these):

public static RoutedCommand NavigateHelp = new RoutedCommand();
In the Page contstructor, you can connect the two:

CommandBindings.Add(new CommandBinding(Commands.NavigateHelp, NavigateHelpExecute));
NavigateHelpExecute can be in the code behind (which is what we do), hook into a ViewModel event handler, or whatever. The beauty of this is that you can disable other navigation like so:

CommandBindings.Add(new CommandBinding(NavigationCommands.Refresh, null));


参考这些文章,

1. 开始WPF / MVVM应用程序:在视图之间导航 [ ^ ]

2. https://techkn0w.wordpress.com/2011/02/22/navigating-between-pages-with-mvvm-light/ [ ^ ]

3. https:// rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/ [ ^ ]
refer these articles,
1. Beginning a WPF/MVVM application: Navigating between views[^]
2. https://techkn0w.wordpress.com/2011/02/22/navigating-between-pages-with-mvvm-light/[^]
3. https://rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/[^]


这篇关于如何使用PRISM从wpf mvvm中的一个页面导航到另一个xaml页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆