Hide WPF elements in Visual Studio designer

后端 未结 7 1849
暗喜
暗喜 2020-11-30 08:39

I have a WPF form which basically looks like this:


  
    
      [content shown during normal operation]
             


        
7条回答
  •  無奈伤痛
    2020-11-30 09:13

    I am on the other side... hate VS 2012 for hiding hidden WPF controls in designer. I need to see them so i have modified gregsdennis code to:

    public class DesignModeTool
    {
        public static readonly DependencyProperty IsHiddenProperty = DependencyProperty.RegisterAttached("IsHidden",   typeof(bool),  typeof(DesignModeTool),   new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnIsHiddenChanged)));
    
        public static void SetIsHidden(FrameworkElement element, bool value)
        {
            element.SetValue(IsHiddenProperty, value);
        }
    
        public static bool GetIsHidden(FrameworkElement element)
        {
            return (bool)element.GetValue(IsHiddenProperty);
        }
    
        private static void OnIsHiddenChanged(DependencyObject d,
                                              DependencyPropertyChangedEventArgs e)
        {
            if (!DesignerProperties.GetIsInDesignMode(d)) return;
            var element = (FrameworkElement)d;
            element.Visibility=Visibility.Visible;
    
        }
    }
    

    wpfClasses2:DesignModeTool.IsHidden="False" will show the control in designer mode.

提交回复
热议问题