【问题标题】:Silverlight binding - Apply Not or ! before binding to Checkbox.IsChecked propertySilverlight 绑定 - 不应用或!在绑定到 Checkbox.IsChecked 属性之前
【发布时间】:2011-10-18 06:25:43
【问题描述】:

我用来将一个类的布尔变量绑定到 Checkbox 的 IsChecked 属性。我想做的是绑定原始值的'NOT',例如IsChecked = Binding Not(IsSelected),请告诉我如何做到这一点。

谢谢

【问题讨论】:

    标签: silverlight data-binding


    【解决方案1】:

    您需要使用转换器。转换器类实现 IValueConverter 并可以将绑定值转换为其他值,在您的情况下,否定它。你可以这样做:

    public class BoolInverseConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool)
                return !(bool)value;
    
            return value;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-27
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多