1
我有一個組合框,其中的項目從0到63的整數值。我想添加選擇所有選項。我如何選擇所有應該選擇的項目?選擇所有組合框內的複選框Wpf中的組合框項目
<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>
視圖模型:
_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
});
}
類:
private List<GenericDescription> _Set2CmdList;
public List<GenericDescription> Set2CmdList
{
get { return _Set2CmdList; }
set { _Set2CmdList = value; }
}
視圖模型的構造
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
我綁定檢查所有作爲複選框的命令,但是當我選擇全選,它不是選擇所有和onproperty布爾顯示錯誤 –