根据选定的组合框项目显示不同的wpf控件 [英] Display different wpf control based on selected combobox item

查看:58
本文介绍了根据选定的组合框项目显示不同的wpf控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的情况来看,让我们举一个例子。如果我选择文本框(组合框中的值),则会在其下方显示一个文本框,否则如果我选择标签(组合框中的值),则会在其下方显示一个标签。我怎样才能实现?

Hi, from my case, lets take an example. If I select textbox(a value in combobox), a textbox will appear below it, else if I select label(a value in combobox), a label will appear below it. How can I make it happen?

推荐答案

这可以通过控制这些控件的可见性来完成。这是可以使用的属性: http:/ /msdn.microsoft.com/en-us/library/system.windows.uielement.isvisible%28v=vs.110%29.aspx [ ^ ]。



此外,您还需要将选定的组合框(也可以推荐列表框)与要显示或隐藏的控件相关联。你需要用一些巧妙的方法来做到这一点。其中一种方法是:您可以在列表项中存储一些信息对象,而不仅仅是字符串。请参阅我以前的回答: combobox.selectedvalue在winform中显示{} [< a href =http://www.codeproject.com/Answers/541683/combobox-selectedvalueplusshowsplus-7b-7dplusinplu#answer1target =_ blanktitle =New Window> ^ ]。



对不起,这个答案是为 System.Windows.Forms 编写的,但这种方法也适用于WPF。 />


-SA
This can be done by controlling the visibility of those controls. This is the property to use: http://msdn.microsoft.com/en-us/library/system.windows.uielement.isvisible%28v=vs.110%29.aspx[^].

Also, you need to associate a selected combo box (list box could also be recommended) with the control to show or hide. You need to use some neat way of doing it. One the the approaches is: you can store some information objects in the list items, not just strings. Please see my past answer: combobox.selectedvalue shows {} in winform[^].

Sorry, this answer is written for System.Windows.Forms, but this approach works for WPF as well.

—SA


这篇关于根据选定的组合框项目显示不同的wpf控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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