[英]Which is the best way to show another window in wpf mvvm
Hi I got some problem with navigating windows in wpf mvvm. 嗨,我在wpf mvvm中浏览窗口时遇到了一些问题。 I got two wpf windows, let's say viewA and viewB. 我有两个wpf窗口,比如说viewA和viewB。 all respective view model are bind to the view using prism prism:ViewModelLocator.AutoWireViewModel="True"
. 所有各自的视图模型都通过使用prism prism:ViewModelLocator.AutoWireViewModel="True"
绑定到视图。
This is my view. 这是我的看法。
<Window x:Class="eBriefcase.WPF.Views.CaseHearing"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="CaseHearing" Height="300" Width="300">
<Grid>
</Grid>
If I want to go to another view, I create new window and use show function in View Model. 如果要转到另一个视图,请创建一个新窗口并在“视图模型”中使用show函数。
ViewB vB_ = new ViewB();
vB_.Show();
when I press show another form button, another duplicate wpf window is open. 当我按显示另一个表单按钮时,将打开另一个重复的wpf窗口。 How can I control it? 我该如何控制? I just studied WPF for only 10 days. 我刚刚学习WPF仅10天。 Is it the correct way of navigating between views? 这是在视图之间导航的正确方法吗?
Best Rgds, df 最佳RGB,DF
The answer is in your question: 答案在您的问题中:
I create new window and use show function 我创建新窗口并使用显示功能
So the new window is shown. 这样便显示了新窗口。 You are being confused with the term view
. 您对术语“ view
感到困惑。 View is not some kind of object in WPF. 视图不是WPF中的某种对象。 It's just logical part of MVVM concepts. 这只是MVVM概念的逻辑部分。 Objects that you operate are Windows
, controls
and pages
. 您操作的对象是Windows
, controls
和pages
。 Looks like you want to use WPF pages
as different views
of your data. 看起来您想将WPF pages
用作数据的不同views
。 There are plenty of manuals on the net about WPF pages
and NavigationService
These are keywords that you need. 网上有很多有关WPF pages
和NavigationService
的手册,这些都是您需要的关键字。
BTW, answering the question in the header: The best method to open windows is to wrap opening windows into some generic WindowManager
and use 顺便说一句,回答标题中的问题:打开窗口的最佳方法是将打开的窗口包装到某些通用WindowManager
并使用
new WindowType(){ DataContext = VM }.Show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.