2016-12-13 18 views
0

私はwpfのコンボボックスからチェック項目を取得するには?

 <UserControl.Resources> 
    <DataTemplate x:Key="cmbIndex"> 
     <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
        Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}" 
        Content="{Binding}" 
        Click="CheckBox_Click"> 

     </CheckBox> 
    </DataTemplate> 
    <CollectionViewSource x:Key="coll" Source="{Binding CMDCollection}"/> 
<UserControl.Resources> 
    <ComboBox Grid.Row="0" 
            HorizontalAlignment="Left" Margin="80,0,0,0" 
            SelectedItem="{Binding T3Command}" 
            Height="20" VerticalAlignment="Center" Width="60" 
            FontFamily="Calibri" FontSize="12"> 
         <ComboBox.ItemsSource> 
          <CompositeCollection> 
           <ComboBoxItem> 
            <CheckBox x:Name="all">Select All</CheckBox> 
           </ComboBoxItem> 
           <CollectionContainer Collection="{Binding Source={StaticResource coll}}"/> 
          </CompositeCollection> 
         </ComboBox.ItemsSource> 
         <ComboBox.ItemTemplate> 
          <DataTemplate> 
           <CheckBox Name="chkTask" Content="{Binding}" IsChecked="{Binding ElementName=all, Path=IsChecked, Mode=OneWay}"></CheckBox> 
          </DataTemplate> 
         </ComboBox.ItemTemplate> 
         <ComboBox.Style> 
          <Style TargetType="{x:Type ComboBox}"> 
           <Setter Property="ItemTemplate" Value="{StaticResource cmbIndex}"/> 
          </Style> 
         </ComboBox.Style> 
        </ComboBox> 

答えて

1

1 ..私はコードを試してみました下..助けが必要コンボボックスにチェックすると、私は、特定のアイテムまたは複数のアイテムを選択するにはどうすればよい、チェックボックスとアイテムとのコンボボックスを持っている)はBool型を追加します。モデルのIsSelectedプロパティ。テンプレートのチェックボックスのIsCheckedプロパティにそのプロパティをバインドします。 2)そのプロパティをItemContainerStyleのComboBoxItemのIsSelectedにバインドします。 Check All(すべてのチェック)機能を使用する(コンバータのような)他のソリューションを考え出すことができます。 これは動作します。

+0

ですが、if(CMDCollection [i] .Isselected)を追加したい場合、Isselectedがリンクしていないというエラーが表示されます。ここで、CMDCollectionはoから63までの整数の観測可能なコレクションです –

関連する問題