我是 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();
}
}
}