简体   繁体   English

WPF MVVM模型中的UserControl视图

[英]UserControl View in WPF MVVM Model

我的MainWindow中有2个UserControl,一个带有一些名称列表,另一个带有ListBox,TextBox和Button。问题是当我运行该应用程序时,我的主窗口应该只带有usercontrol1,而当我单击名称时usercontrol2应该在我的主窗口上打开。我该如何实现,我是新手,请帮助我

There are several ways that we could achieve your requirements. 我们有几种方法可以满足您的要求。 However, none of them have anything to do with Visibility , so perhaps your title could do with an edit? 但是,它们都与Visibility无关,所以也许您的标题可能与编辑有关?

Either way, I just answered a similar question just a few hours ago (always a good reason to search for an answer before you ask a question here) which would answer your question. 无论哪种方式,我都只是在几个小时前回答了一个类似的问题(总是一个很好的理由,在您在此处提出问题之前先寻找答案),它将回答您的问题。 Please take a look at the WPF MVVM navigate views question here on StackOverflow for an answer to your question. 请在StackOverflow上的WPF MVVM导航视图问题中查看问题的答案。

While it might not answer all of your requirements, I trust that you can successfully apply it to your situation. 尽管它可能无法满足您的所有要求,但我相信您可以成功地将其应用于您的情况。 However, if you need further help, just leave me a comment. 但是,如果您需要进一步的帮助,请给我留言。

you can toggle between hiding and making control using VisiblityProperty 您可以使用VisiblityProperty在隐藏和进行控制之间切换

Bind the properties VisiblityProperty and change its value depending on your logic 绑定属性VisiblityProperty并根据您的逻辑更改其值

refer the below links 请参考以下链接

Binding Visibility Converter in WPF C# WPF C#中的绑定可见性转换器

http://jeffhandley.com/archive/2008/10/27/binding-converters---visibilityconverter.aspx http://jeffhandley.com/archive/2008/10/27/binding-converters---visibilityconverter.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM