Triggers collection members must be of type EventTrigger

前端 未结 4 1314
一生所求
一生所求 2020-12-16 10:24

I\'ve created a UserControl, similar to the following:


    

        

        
4条回答
  •  無奈伤痛
    2020-12-16 10:43

    You could also bind the Visibility in your stackpanel to the IsChecked property in the ToggleButton. You would need to use a custom ValueConverter. Here is one I found online:

    ///   
    /// WPF/Silverlight ValueConverter : Convert boolean to XAML Visibility
    ///   
    [ValueConversion(typeof(bool), typeof(Visibility))]
    public class VisibilityConverter : IValueConverter
    {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
        return (value != null && (bool)value) ? Visibility.Visible : Visibility.Collapsed;
      }
    
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
      {
        Visibility visibility = (Visibility)value;
        return (visibility == Visibility.Visible);
      }
    }
    

提交回复
热议问题