WPF 组合框默认值(请选择) [英] WPF Combobox DefaultValue (Please Select)
本文介绍了WPF 组合框默认值(请选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 WPF 组合框,它显示了枚举列表.代码如下.
Hi I have a WPF Combobox which shows a list of Enums. Code is below.
<ComboBox HorizontalAlignment="Left"
Margin="139,299,0,0"
VerticalAlignment="Top"
ItemsSource="{Binding Source={StaticResource Enum}}"
Width="78"/>
但是,当视图加载时,它显示列表中的第一个枚举,但我希望它显示请选择",所以是否有 XAML 来执行此操作(如果需要,视图中的 C# ..)
However, when the view is loaded, it shows the first enum in the list, but I would like it to show 'Please Select', so is there XAML to do this (C# in the view if needs be..)
谢谢
推荐答案
已提供所有好的答案,但我使用以下方法解决了我的问题
All good answers that has been supplied, but I used the following to solve my problem
<ComboBox SelectedIndex="0">
<ComboBox.ItemsSource>
<CompositeCollection>
<ListBoxItem>Please Select</ListBoxItem>
<CollectionContainer Collection="{Binding Source={StaticResource YOURDATASOURCE}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
感谢所有帮助过的人!
这篇关于WPF 组合框默认值(请选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文