我有兩個按鈕WPF在我的應用程序綁定按鈕
現在我想的btnOff結合!ISON。意思是btnOn爲Enabled,btnOff應該被禁用,反之亦然
編輯:下面是我的實現:
<Button x:Name="btnOn" Content="On" Width="45" Height="24" IsEnabled="{Binding isOn, Converter={StaticResource BoolInverter}}" />
<Button x:Name="btnOff" Content="Off" Width="45" Height="24" IsEnabled="{Binding isOn} />
public class BoolInverterConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
{
return !(bool)value;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
{
return !(bool)value;
}
return value;
}
}
到目前爲止你有什麼? –
我實現了轉換器來反轉布爾值,它現在工作正常。 – xaria