我有一个DataGrid
. DataGridCheckBoxColumn
网格具有与对象列表的绑定。我想要的是,如果选中了 N 个复选框,则未选中的会被禁用,但我不知道如何执行禁用。
<DataGridCheckBoxColumn
x:Name="IsFixedByBracketColumn"
Header="Fissato con staffa"
Binding="{Binding isFixedByBracket, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="False">
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition
Binding="{Binding
HasMaxNumberReached,
RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
Value="true"/>
<Condition
Binding="{Binding
IsChecked,
RelativeSource={RelativeSource Self}}"
Value="false"/>
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="False"/>
</MultiDataTrigger>
</Style.Triggers>
<EventSetter
Event="CheckBox.Checked"
Handler="DataGridCheckBoxColumn_Checked" />
</Style>
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
活动代码:
private void DataGridCheckBoxColumn_Checked(object sender, RoutedEventArgs e)
{
CheckBox cb = (CheckBox)sender;
if (cb.IsChecked == true)
{
this.numberOfCheckboxesChecked++;
}
else
{
this.numberOfCheckboxesChecked--;
}
if (this.numberOfCheckboxesChecked >= maxNumOfPointsPerSide)
{
this.HasMaxNumberReached = true;
}
else
{
this.HasMaxNumberReached = false;
}
}
public bool HasMaxNumberReached
{
get {
return hasMaxNumberReached;
}
set {
hasMaxNumberReached = value;
RaisePropertyChanged("HasMaxNumberReached");
}
}