我想在MVVM WPF中关闭用户控件 [英] I want to close a User Control , in MVVM WPF
本文介绍了我想在MVVM WPF中关闭用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个用户控件,我可以关闭整个应用程序......但我只想关闭用户控件。我没有在应用程序中添加用户控件,并从应用程序中删除了用户控件..
这是我在mvvm中用来打开用户控件的代码
窗口窗口=新窗口
{
Title =Sl ,
内容=新视图,
DataContext = new ViewModel()
};
I have created a user control , i'm able to close the whole app... but i want to close only the user control. I have not added the user control in the app, and removed the user control from the app..
this is the code i used in mvvm to open the user contol
Window window = new Window
{
Title = "Sl",
Content = new View,
DataContext = new ViewModel()
};
推荐答案
没有关闭控件这样的概念。我不认为这样的概念,如果存在的话,可能有用。您可以:1)隐藏用户控件(如果不再需要),可能是暂时的; 2)永久删除逻辑树中的控件。
请参阅:
http://msdn.microsoft.com/en-us/library/ system.windows.uielement.isvisible(v = vs.110).aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.uielement.visibility(v = vs.110).aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.visibility%28v=vs.110%29.aspx [ ^ ],
http:// msdn .microsoft.com / zh-CN / library / ms753391%28v = vs.110%29.aspx [ ^ ]。
也许你需要了解一件事:UI概念开放和关闭只不过是成语;而那些成语甚至都不太精确:你不是真的开放或关闭任何东西:你创建一个窗口,展示它,暂时隐藏或永久处置。我认为这些成语的唯一真正原因是一个简单的事实:因为窗口被称为窗口,具有物质生命原型的东西可以真正打开和关闭。计算机用户界面中这些术语的类似物与这些原始概念相差甚远。
-SA
There is no such concept as "closing a control". And I don't think that such concept, if existed, could be of any use. You can: 1) hide the user control if it is no longer needed, maybe temporarily; 2) permanently remove the control from the logical tree.
Please see:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.isvisible(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.uielement.visibility(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.visibility%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx[^].
Perhaps you need to understand one thing: the UI notions "open" and "close" are nothing but idioms; and those idioms are not even too precise: you are not really open or close anything: you create a window, show it, hide it temporarily or permanently dispose. I think the only real reason for these idioms is the simple fact: because window is called "window", something with a material life prototype which can really be opened and closed. The analogs of these terms in computer UI are quite far from these original notions.
—SA
这篇关于我想在MVVM WPF中关闭用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文