转换我的多窗口WPF应用程序到一个窗口? [英] Converting my multi window WPF app to one window?

查看:119
本文介绍了转换我的多窗口WPF应用程序到一个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了打开基于用户交互连续窗口一个WPF应用程序。例如,第一winodw问什么模块的用户希望在工作时,做出选择和一个按钮按下时,一个新窗口打开,显示一些厂商和汇总数。选择这些供应商之一,推动编辑按钮打开另一个窗口,显示该供应商的详细信息。点击一个细节,然后一个按钮打开另一个窗口,用户可以改变一些数字等,然后用户关闭该窗口,挑选不同的项目和编辑,或关闭该窗口,并挑选不同的供应商等,每个窗口都有自己的当前视图模型。我想摆脱Windows的所有层的。选项卡控件似乎并没有成为一个不错的选择,因为用户将不得不通过正确的顺序是什么等等来改变这种只使用一个窗口的最佳方式,而换出用户可以看到在一个窗口什么当他,例如,按下一个按钮,编辑等?

I made a WPF app that opens successive windows based on user interaction. For example, the first winodw asks what module the user wants to work on, when a selection is made and a button pushed, a new windows open showing some Vendors and summary counts. Selecting one of those vendors and pushing the Edit button opens another window that shows the details of that Vendor. Clicking a detail and then a button open yet another window where the user can change some numbers etc. Then the user closes that window, picks a different item and edits, or closes that window and picks a different vendor etc. Each window has its own view model currently. I want to get rid of all the layers of windows. Tab Control doesn't seem to be a good option, since the user will have to go through the correct sequences etc. What is the best way to change this to use only one window, and swap out what the user sees in the one window when he, for example, pushes a button to edit etc.?

推荐答案

我个人更喜欢使用< ContentControl中/> 对于我的内容区域中,及换出根据用户的当前的窗口

Personally I prefer to use a <ContentControl /> for my content area, and to swap out the active content based on the user's current "window"

在我的博客一个例子,你可以看到这一点,但基本组成是这样的:

I have an example on my blog that you could look at, but the basic components look like this:

视图模型:

ObservableCollection<IViewModel> AvailableScreens;
IViewModel ActiveScreen;

ICommand SetActiveScreenCommand;

通过一些XAML看起来像这样:

With some XAML that looks like this:

<ContentControl Content="{Binding ActiveScreen}" />

和我通常使用的DataTemplates 来告诉WPF如何绘制每个视图模型

And I usually use DataTemplates to tell WPF how to draw each ViewModel

<Window.Resources>
    <DataTemplate DataType="{x:Type local:ModulesViewModel}">
        <local:ModulesView />
    </DataTemplate>

    <DataTemplate DataType="{x:Type local:VendorsViewModel}">
        <local:VendorView />
    </DataTemplate>

    <DataTemplate DataType="{x:Type local:EditVendorViewModel}">
        <local:EditVendorView />
    </DataTemplate>
</Window.Resources>

这篇关于转换我的多窗口WPF应用程序到一个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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