我想要在我的组合框中有一个默认文本,因为我已将组合框绑定(bind)到某些项目列表...这是我的 xaml 文件代码。
<ComboBox x:Name="ProjectComboBox"
Text="{Binding ProjectNameBinding}"
ItemsSource="{Binding projectList, ElementName=MainWin}"
SelectedValuePath="_id" DisplayMemberPath="_name"
SelectedItem="{Binding ProjectNameBindingClass, Mode=OneWayToSource}"
Width="130" Background="White" BorderThickness="1"
FontFamily="/TimeSheet;component/Resources/#Open Sans" FontSize="12"
Canvas.Right="159" Canvas.Top="8" Height="47">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding _name}" TextWrapping="Wrap"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
最佳答案
您尝试过文本属性
<ComboBox x:Name="ProjectComboBox"
IsEditable=True
Text="{Binding ProjectNameBinding}" ....../>
或
您可以使用 SelectedIndex 属性并将其设置为 0(SelectedIndex=0),这会显示给定源中的第一项。
或
您可以像链接 How to display default text "--Select Team --" in combo box on pageload in WPF? 中那样执行此操作
关于c# - 组合框的默认文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22558536/