我是WPF Binding的新手,并且在选中CheckBox“RunOnce”时尝试禁用名为“GrpRecurEndDate”的GroupBox。我尝试按照下面的帖子,但没有太多运气获得绑定工作。任何帮助将不胜感激。
WPF binding declarative syntax: enable a GroupBox when a checkbox is NOT set
我的复选框如下:
<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:
<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();
}
}
}