WPF MVVM模型中的UserControl可见性 [英] UserControl Visibility in WPF MVVM Model

查看:247
本文介绍了WPF MVVM模型中的UserControl可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have 2 UserControls in my MainWindow,one is with list of some names and the other is with a ListBox,TextBox and Button.The problem is when i run the application my mainwindow should be only with usercontrol1 and when i click on the name the usercontrol2 should open on my mainwindow.How can i achieve this,I'm new to this please help me

推荐答案

我想你的第二个用户控件正在显示列表框中所选项目的数据?



如果是这样,那么将列表框的SelectedItem属性绑定到ViewModel将告诉您是否选择了某些内容,如果是,它是什么。



然后,您可以通过转换器将第二个用户控件的可见性绑定到相同的SelectedItem属性 - 转换器返回Visibility.Collapsed(或隐藏)如果输入值为Null,则返回Visibility.Visible,如果不是。
I guess your second user control is displaying data from the selected item in the list box?

If so, then binding the listbox's SelectedItem property to your ViewModel will tell you if something is selected and, if so, what it is.

You could then bind the visibility of your second user control, via a converter, to the same SelectedItem property - the converter returning Visibility.Collapsed (or Hidden) if the input value is Null, and returning Visibility.Visible if not.


这篇关于WPF MVVM模型中的UserControl可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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