私は0〜63の整数値の項目を持つコンボボックスを持っています。私はすべてのオプションを選択して追加します。私はすべての項目を選択する必要がありますすべてを選択した場合、私はどのように働くことができますか?WpfのComboboxアイテム内のSelectAllチェックボックス
<DataTemplate x:Key="cmbIndex">
<CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
Content="{Binding Name}" Name="chkbox"
Click="CheckBox_Click">
</CheckBox>
</DataTemplate>
<CollectionViewSource x:Key="coll" Source="{Binding Set2CmdList,UpdateSourceTrigger=PropertyChanged}"/>
<ComboBox Grid.Row="0" SelectedIndex="{Binding Set2SelectedIndex}"
HorizontalAlignment="Left" Margin="80,0,0,0"
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.Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="ItemTemplate" Value="{StaticResource cmbIndex}"/>
</Style>
</ComboBox.Style>
</ComboBox>
ビューモデル:のviewmodelの
private List<GenericDescription> _Set2CmdList;
public List<GenericDescription> Set2CmdList
{
get { return _Set2CmdList; }
set { _Set2CmdList = value; }
}
コンストラクタ:
_CMDCollection = new ObservableCollection<int>();
_Set2CmdList = new List<GenericDescription>();
_Set2CmdList.Add(new GenericDescription() { Name="Select All",IsSelected=false });
for (int i = 0; i < 64; i++)
{
_CMDCollection.Add(i);
_Set2CmdList.Add(new GenericDescription()
{
Name = i.ToString(),
IsSelected = false
});
}
クラス:
public class GenericDescription
{
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value;}
}
private bool _IsSelected;
public bool IsSelected
{
get { return _IsSelected; }
set { _IsSelected = value; }
}
}
それは動作していません –
詳細な問題は何かを教えてください。 – Eldho
私はcheckboxにすべてコマンドをチェックしてバインドしましたが、select allを選択すると、ブール値エラーを表示するためにすべてとオンプロパティを選択していません –