如何添加选项"所有"在WPF组合框与数据库绑定组合、绑定、选项、数据库

2023-09-03 02:44:04 作者:超越自已

我有如下的组合框在WPF。我知道,我可以CompositeCollection添加选项所有,但我不知道怎么办。这将是巨大的,如果有人帮我了一个简短的教程。

 <组合框的SelectionChanged =ComboBoxOperatingPoints_SelectionChanged
          X:名称=ComboBoxOperatingPoints
          DropDownOpened =ComboBoxOperatingPoints_DropDownOpened_1
          字号=30
          的Horizo​​ntalAlignment =右
          保证金=40,40,0,0
          VerticalAlignment =热门
          宽度=200
          身高=50
          IsSynchronizedWithCurrentItem =真
          的ItemsSource ={结合OperatingPoints}
          的DisplayMemberPath =名
          的SelectedValue ={结合OperatingPointID,UpdateSourceTrigger =的PropertyChanged,TargetNullValue =''}
          SelectedValuePath =operating_point_id>
< /组合框>
 

解决方案

试试这个(msdn):

 <组合框X:​​名称=ComboBoxOperatingPoints
          的SelectionChanged =ComboBoxOperatingPoints_SelectionChanged
          WIDTH =200高度=50
          IsSynchronizedWithCurrentItem =真
          的DisplayMemberPath =名
          SelectedValuePath =operating_point_id>
    < ComboBox.Resources>
        < CollectionViewSource X:关键=comboBoxSource来源={绑定路径= OperatingPoints}/>
    < /ComboBox.Resources>
    < ComboBox.ItemsSource>
        < CompositeCollection>
            <地方:OpPoint名称=所有operating_point_id = -  1/>
            < CollectionContainer集={绑定源= {的StaticResource comboBoxSource}}/>
        < / CompositeCollection>
    < /ComboBox.ItemsSource>
< /组合框>
 

WPF 怎么添加数据库的导航就像windowws form那样

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>

解决方案

Try this (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>