我想在wpf中打开另一个用户控件并关闭打开的用户控件 [英] i want to open another user control and close open user control in wpf

查看:160
本文介绍了我想在wpf中打开另一个用户控件并关闭打开的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在wpf中打开另一个用户控件并关闭打开的用户控件

i want to open another user control and close open user control in wpf

推荐答案

请参阅我对该问题的评论。



当你尝试操作不存在的概念时,我真的不知道你真正想做什么,但你很可能只想删除一个控件并用另一个控件替换它。所有问题都是:在哪里?或者,您可以简单地隐藏一个控件并显示另一个控件。



隐藏/显示的方法将是最简单的,也许更合适,特别是如果您的数量有限这些控制。具体如下:

UIElement.IsVisible Property(System.Windows) [ 1 ],

UIElement.Visibility Property(System.Windows) [ 2 ]。



要添加和删除控件,您还需要学习一些东西。首先,你不只是添加控制;你必须将它添加到某个父元素,到逻辑树的某个点。请参阅:

WPF中的树木 [< a href =https://msdn.microsoft.com/library/ms753391%28v=vs.100%29.aspxtarget =_ blanktitle =New Window> 1 ],
WPF中的树木 [ 2 ],

WPF中的树木 [ 3 ],

WPF内容模型 [ 4 ],

WPF内容模型 [ 5 ],

WPF内容模型 [ 6 ]。



您不需要一次挖掘所有细节;首先,你只需掌握主要思想。看看最后的链接。他们描述了您可能面临的两个主要案例(太糟糕了,您没有告诉我们您的控件应该在哪里)。在第一种情况下,您的控件是其父元素的唯一元素,即 Content 。因此,通常,您将父元素的属性 Content 分配给另一个的一个控件实例;这些不同控件的类型也可以不同;它应该从内容模型基础知识中理解它。



还有其他情况,你可以在同一个MSDN页面上阅读它们。



其他案例是包含任意对象集合的控件。然后从集合中删除一个项目,并将另一个项目添加到同一集合中。最典型的情况是类 ItemsControl



......等等。我不能也不想在此列出所有案例;它在我引用的页面上做得非常好。你只需要明白这个想法。



-SA
Please see my comment to the question.

As you try to operate concepts which don't exist, I cannot really know what you really want to do, but it's very likely that you simply want to remove one control and replace it with another one. All question is: where? Alternatively, you can simply hide one control and show another one.

The approach with hiding/showing would be the simplest and perhaps more suitable, especially if you have limited number of such controls. This is how:
UIElement.IsVisible Property (System.Windows)[1],
UIElement.Visibility Property (System.Windows)[2].

To add and remove controls, you need too learn something. First of all, you don't just add control; you have to add it to certain parent element, into some point of your logical tree. Please see:
Trees in WPF[1],
Trees in WPF[2],
Trees in WPF[3],
WPF Content Model[4],
WPF Content Model[5],
WPF Content Model[6].

You don't need to dig in all the detail at once; at first, you only need to grasp the main ideas. Look at the last too links. They describe two major cases you may face with (too bad you did not tell us where your controls should be). In first case, your control is the only element of its parent element, its Content. So, typically, you assign the property Content of your parent element with one control instance of another; the types of those different controls can also be different; it should understand it from the content model fundamentals.

There are other cases, you can read about them on the same MSDN page.

The other cases are "Controls That Contain a Collection of Arbitrary Objects". Then you remove one item from collection and add another one to the same collection. Most typical case is the class ItemsControl.

…And so on. I cannot and don't want to list all cases here; it's done very nicely on the page I referenced. You just need to get the idea.

—SA


这篇关于我想在wpf中打开另一个用户控件并关闭打开的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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