如何使用PRISM从wpf

如何使用PRISM从wpf

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

问题描述

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

Hi can anyone give any example

推荐答案

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).


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));



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

09-04 20:07