WPF绑定中的公式
您需要使用转换器来实现这一点。
public class BooleanNegationConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return ConvertValue(value); } private bool ConvertValue(object value) { bool boolValue; if(!Boolean.TryParse(value.ToString(), out boolValue)) { throw new ArgumentException("Value that was being converted was not a Boolean", "value"); } return !boolValue; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return ConvertValue(value); } }
然后使用它,就像这样:
记住,您必须在xaml资源中声明此静态资源。像这样: