Hide WPF elements in Visual Studio designer Hide WPF elements in Visual Studio designer wpf wpf

Hide WPF elements in Visual Studio designer


Starting from VS2012 you can just use the Blend namespace IsHidden attribute:

  • add if not already present xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  • put d:IsHidden="true" on element you want to hide at design time only


Nice solution, I was having a similar problem and I agree that there are cases where it's needed. Here is a minor update that allows you to edit the value to turn IsHidden on and off while designing. I also applied a ScaleTransform instead of setting Width and Height to reduce screen artifacts a bit if control grips etc are displayed and to avoid conflicts if the control being hidden already has Width and Height properties set (assuming that the control doesn't already have a LayoutTransform set on it).

Public Class DesignModeTool  Public Shared ReadOnly IsHiddenProperty As DependencyProperty = DependencyProperty.RegisterAttached( _    "IsHidden", GetType(Boolean), GetType(DesignModeTool), _    New FrameworkPropertyMetadata(False, New PropertyChangedCallback(AddressOf OnIsHiddenChanged)))  Public Shared Sub SetIsHidden(ByVal element As FrameworkElement, ByVal value As Boolean)    element.SetValue(IsHiddenProperty, value)  End Sub  Public Shared Function GetIsHidden(ByVal element As FrameworkElement) As Boolean    Return DirectCast(element.GetValue(IsHiddenProperty), Boolean)  End Function  Private Shared Sub OnIsHiddenChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)    If System.ComponentModel.DesignerProperties.GetIsInDesignMode(d) AndAlso True.Equals(e.NewValue) Then      With DirectCast(d, FrameworkElement)        .LayoutTransform = New ScaleTransform(0.001, 0.001)      End With    ElseIf System.ComponentModel.DesignerProperties.GetIsInDesignMode(d) AndAlso False.Equals(e.NewValue) Then      With DirectCast(d, FrameworkElement)        .LayoutTransform = Nothing      End With    End If  End SubEnd Class 


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;    }}