MVVM模式中UserControl上的模态弹出窗口 [英] Modal Popup on UserControl in MVVM pattern

查看:420
本文介绍了MVVM模式中UserControl上的模态弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用WPF和MVVM模式C#的窗口应用程序。



有一个MainWindow,作为容器窗口,根据要求加载/卸载不同的UserControl。

现在,在UserControl上,我有一个显示可用项目的网格和一个UserControl底部的添加项目按钮。在这个按钮上单击,执行一个命令,我想打开一个模式弹出窗口,其中包含2个文本框,确定和取消按钮(在UserControl上将一些新项添加到网格中)。并且想要使用与我的父UserControl的viewmodel相同的viewmodel绑定文本框和按钮命令。



请建议,优化方式来实现这一目标...



谢谢和问候,

Zaheer

Hi All,

I am working on a window application using WPF with MVVM pattern C#.

There is a MainWindow, as a container window, where different UserControls loaded/unloaded according to the requirements.
Now, on a UserControl, I have a grid showing available items and one "Add Items" button at the bottom of the UserControl. On this button click, execute a command and, i want open a modal popup with 2 textboxes, OK and Cancel buttons(Add some new items into a Grid on UserControl). And want to bind textboxes and button commands with same viewmodel as my parent UserControl's viewmodel.

Kindly suggest, optimized way to achieve this...

Thanks and Regards,
Zaheer

推荐答案

从你的描述中我会想到有一个基地查看能够在窗口或现有控件中显示自身的类。



因此,当您加载/卸载视图时,您可以将视图告诉View将自己加载到某个容器中(可能就像现在一样)或者将自己弹出到窗口中。



我在MVVM文章中做了类似的事情在其中 [ ^ ]
From your description I would think about having a base View class that has the ability of showing itself in a window or in an existing control.

So, when you load/unload a view you can tell the View to either load itself into some container (as it presumably does now) or to pop itself up into a window.

I do something similar in my MVVM articles here[^]


这篇关于MVVM模式中UserControl上的模态弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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