チェックボックスが無効になっている場合、値を変更することはできません。
MVVM でこれを行うには、メインのチェックボックスを無効にする前に値を変更する必要があります。
c#
/// <summary>
/// Bind to IsChecked of "ControlchkEnable" element (TwoWay)
/// and bind to IsEnabled of each of other 7 checkbox's (OneWay)
/// </summary>
public bool ControlchkEnable
{
get { return _controlchkEnable; }
set
{
if (value == _controlchkEnable) return;
_controlchkEnable = value;
// Before informing the checkboxes are disabled,
// pass their values to uncheck
if (!_controlchkEnable)
{
Check1 = false;
// Check2 = false;
// Check...= false;
}
// Raise UI that value changed
RaisePropertyChanged("ControlchkEnable");
}
}
private bool _controlchkEnable;
/// <summary>
/// Bind to IsChecked of one of other 7 checkbox's (TwoWay)
/// </summary>
public bool Check1
{
get { return _check1; }
set
{
if (value == _check1) return;
_check1 = value;
RaisePropertyChanged("Check1");
}
}
private bool _check1;
XAML :
<!-- Main checkbox -->
IsChecked="{Binding ControlchkEnable, Mode=TwoWay}"
<!-- Other checkbox's -->
IsEnabled="{Binding ControlchkEnable, Mode=OneWay}"
IsChecked="{Binding Check1, Mode=TwoWay}"