且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何添加选项“全部"从数据库绑定到 WPF 中的组合框

更新时间:2023-08-17 15:55:04

试试这个 (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>