私はWPFバインディングを初めて使用し、CheckBoxの「RunOnce」がチェックされているときに「GrpRecurEndDate」と呼ばれるGroupBoxを無効にしようとしています。以下の投稿をたどってみましたが、バインディングを機能させることができませんでした。どんな助けでも大歓迎です。
WPF バインディング宣言構文: チェックボックスが設定されていないときに GroupBox を有効にする
私のチェックボックスは次のとおりです。
<RadioButton Content="Recurring" Height="16" HorizontalAlignment="Left" Margin="26,12,0,0" Name="RecurringArchive" VerticalAlignment="Top" IsChecked="True" Width="124" Checked="RecurringArchive_Checked"/>
<RadioButton Content="Run Once" Height="16" HorizontalAlignment="Left" Margin="156,12,0,0" Name="RunOnce" VerticalAlignment="Top" Grid.Column="1" IsEnabled="True" Width="77" Checked="RunOnce_Checked"/>
私のグループボックス:
<GroupBox Header="Recurrence End Date" Height="72" Margin="12,267,12,0" Name="GrpRecurEndDate" VerticalAlignment="Top" IsEnabled="{Binding ElementName=RecurringArchive, Path=IsChecked, Converter={StaticResource DisableGroupBoxConverter}}"></GroupBox>
コンバーターの私のコード:
[ValueConversion(typeof(bool), typeof(bool))]
public class DisableGroupBoxConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (targetType != typeof(bool))
throw new InvalidOperationException("The target must be a boolean");
return !(bool)value;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
}