2011-10-18 50 views

回答

5

您需要使用轉換器。一個convertor類實現了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(); 
    } 
}