Hide WPF elements in Visual Studio designer

后端 未结 7 1865
暗喜
暗喜 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:08

    Nice work! I translated to C# and change the property it's changing to RenderTransform.

    static 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.RenderTransform = (bool)e.NewValue
               ? new ScaleTransform(0, 0)
               : null;
        }
    }
    

提交回复
热议问题