2012-05-24 103 views
1

上能見度我有這樣的結合WPF按鈕的可見性問題

Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" 

我想設置Visibility = False如果ComputedVerticalScrollBarVisibility = TrueVisibility = True如果ComputedVerticalScrollBarVisibility = false

有沒有這樣的事情:

Visibility="!{TemplateBinding ComputedVerticalScrollBarVisibility}" 

感謝 Sai

回答

2

哈桑的觀點,這裏的轉換是非常簡單的:

public class VisibilityInverterConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     if (value != null && value is Visibility) 
     { 
      var vis = (Visibility) value; 

      if (vis == Visibility.Hidden || vis == Visibility.Collapsed) 
      { 
       return Visibility.Visible; 
      } 

      return Visibility.Collapsed; 
     } 

     return Visibility.Visible; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 
+0

得到一個錯誤:設置屬性「System.Windows.Data.Binding.Path」引發了異常。 代碼:Visibility =「{Binding Path = {TemplateBinding ComputedVerticalScrollBarVisibility},Converter = {StaticResource VisibilityInverter}}」>> –

+0

什麼是例外? – Robaticus