根据用户对下拉列表的选择显示控件
我需要根据用户在下拉列表中所做的选择来显示不同的控件。也就是说,如果用户对日期进行选择,则应显示日期选择控件,或用于文本输入的文本输入框......或者用于更复杂选择的一组控件。
因此,我们的想法是创建任意数量的用户控件,然后在需要的时间显示所需的控件。我想要比“可见的真/假”属性更优雅的东西。
I need to display different controls depending on what selection a user makes in a drop down. That is, if the user makes a selection for a date, a date selection control should display, or text input box for text input... Or a set of controls for more complex selections.
So the idea is to create how ever many user controls, and then display the required one at the required time. I want something more elegant than faffing with 'visible true/false' properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用内容控制和数据触发器来实现它。无需玩弄可见性。
这是一个示例,可以让您清楚地了解。
在下面的示例中,我采用了一个内容控件,其中组合框所选项目作为数据上下文。
XAML 代码:
代码隐藏:
注意:为了创建示例,我使用了代码隐藏...您可以轻松地将其转换为 MVVM
You can achieve it using content control and data triggers. No need to play with Visibility.
Here is a sample which will give you clear idea.
In the below sample i have taken a content control with combo box selected item as datacontext.
XAML Code:
Code Behind:
Note: For creating a sample i have used code behind... you can easily convert it to MVVM
:-) 无论如何,你最终都会这样做......
这太微不足道了......任何像样的 WPF 相关教程都会帮助你......
只是为了快速开始,你将不得不使用
Binding
ComboBox 的SelectedItem
以及您想要通过适当的值转换器隐藏/显示的所有控件的Visibility
。:-) You will land up doing exactly that anyways....
This is too trivial ... any decent WPF related tutorial will help you with this...
Just for a quick start, you will have to use
Binding
of ComboBox'sSelectedItem
withVisibility
of all those controls you want to hide/show through a proper value converter.