2013-09-07 11 views
5

WPFには次のようなものがあります。私はオプションALLをCompositeCollectionに追加できることを知っていますが、私はどのように分かりません。誰かが短いチュートリアルで私を助けてくれれば素晴らしいだろう。データベースからのバインディングを使用してWPFのコンボボックスに「すべて」オプションを追加する方法

<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> 
+0

は、このユーザーコントロールをダウンロード: http://www.codeproject.com/Articles/563862/Multi-Select-ComboBox-in-WPF –

+1

@eranotzap申し訳ありませんが、私はこの仕事のカスタムコントロールを使用する必要はありません。私が知っているように、CompositeCollectionでこれが可能です。これを行う方法がある場合は、それを学びたいと思います。 –

答えて

8

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> 
+0

うまく働いてくれてありがとう。 –

関連する問題