为ComboBox设置默认值 [英] Set Default Value For ComboBox
问题描述
试图对此进行一些搜索,但无法找到我所需要的。我想有一个带有硬编码项目的组合框,但包含一个默认字符串。例如:
Tried to do some searching on this, but couldn't find exactly what I needed. I'd like to have a combobox with hardcoded items, but contain a default string. For example:
- 选择项目 -
--Select Item--
Item1
Item2
Item3
我不想显示--Select Item在列表中,只有在组合框本身。
此外,我不希望此值可编辑。
I do not want the --Select Item-- to appear within the list, only on the combobox itself. Also I do not want this value to be editable.
感谢。
推荐答案
您可以覆盖默认模板并在其中包含一个TextBlock,如果 SelectedItem
null
(使用datatrigger的样式)。要获取默认十诫,您可以修改检查MSDN ( Default WPF Themes
link)。
You could override the default template and to include a TextBlock there which only is visible if the SelectedItem
is null
(use a style with datatrigger for that). To get a default tenmplate you can modify check MSDN (Default WPF Themes
link).
这篇关于为ComboBox设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!