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>
感谢大家谁帮助!
Thanks for everyone who has helped!
这篇关于WPF组合框默认值(请选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文