如何添加选项“全部"从数据库绑定到 WPF 中的组合框 [英] How to add option "All" to a combobox in WPF with binding from Database
本文介绍了如何添加选项“全部"从数据库绑定到 WPF 中的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 WPF 中有以下 ComboBox
.我知道我可以使用 CompositeCollection 添加选项 ALL
,但我不知道如何.如果有人能帮我提供一个简短的教程,那就太好了.
I have the following ComboBox
in WPF. I know that I can add option ALL
with CompositeCollection, but I don't know how. It would be great if somebody help me out with a short tutorial.
<ComboBox SelectionChanged="ComboBoxOperatingPoints_SelectionChanged"
x:Name="ComboBoxOperatingPoints"
DropDownOpened="ComboBoxOperatingPoints_DropDownOpened_1"
FontSize="30"
HorizontalAlignment="Right"
Margin="40,40,0,0"
VerticalAlignment="Top"
Width="200"
Height="50"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding OperatingPoints}"
DisplayMemberPath="name"
SelectedValue="{Binding OperatingPointID,UpdateSourceTrigger=PropertyChanged,TargetNullValue=''}"
SelectedValuePath="operating_point_id">
</ComboBox>
推荐答案
试试这个 (msdn):
<ComboBox x:Name="ComboBoxOperatingPoints"
SelectionChanged="ComboBoxOperatingPoints_SelectionChanged"
Width="200" Height="50"
IsSynchronizedWithCurrentItem="True"
DisplayMemberPath="name"
SelectedValuePath="operating_point_id">
<ComboBox.Resources>
<CollectionViewSource x:Key="comboBoxSource" Source="{Binding Path=OperatingPoints}" />
</ComboBox.Resources>
<ComboBox.ItemsSource>
<CompositeCollection>
<local:OpPoint name="all" operating_point_id="-1" />
<CollectionContainer Collection="{Binding Source={StaticResource comboBoxSource}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
这篇关于如何添加选项“全部"从数据库绑定到 WPF 中的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文