How to make the control hidden by default displayed in the designer of WPF Visual Studio 2010?

I have a control that has hidden visibility because it is bound to a property in the view model, whose default value makes it hide. I can access it through XAML, but I would like it to still show up in the designer.

Is there a clean way to do this? For now, I manually edit the Visibility attribute to display it, but I don’t want to do this if I forget to change it.

+6
source share
3 answers

Not sure if it is much cleaner, but you should install it on Visible in ctor (before initialization);

+2
source

You can bind to the DesignerProperties.IsInDesignMode boolean property, which is true only if you are inside the designer. Here is an example:

 <Window x:Class="Visitest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cm="clr-namespace:System.ComponentModel;assembly=PresentationFramework" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <BooleanToVisibilityConverter x:Key="conv"/> </Window.Resources> <Grid> <TextBox Margin="8" Background="Green" Visibility="{Binding (cm:DesignerProperties.IsInDesignMode), RelativeSource={RelativeSource Self}, Converter={StaticResource conv}}"/> </Grid> </Window> 
+4
source

Have you seen Hide WPF Elements in Visual Studio Designer ? It seems that other people have solved the problem by creating a simple user extension.

+1
source

Source: https://habr.com/ru/post/911692/


All Articles