Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design-time-only background color in WPF?

In WPF XAML there is the convenient DesignHeight and DesignWidth, for instance in code as

<UserControl ... d:DesignHeight="500" d:DesignWidth="500" ... /> 

which is great because I can build the layout with a representative, but not locked-in, control size.

However, I'm often building dark UIs, where labels and so forth need to be white, but my controls still need a transparent background color. This creates a design-time inconvenience because white seems to be the default background color for transparent controls in the designer, leading to unreadable white-on-white labels.

Is there a way or strategy for setting the design-time background color, with similar convenience as DesignHeight/DesignWidth?

like image 281
DuckMaestro Avatar asked Jan 31 '12 08:01

DuckMaestro


2 Answers

There's an undocumented property d:DesignStyle of type Style that you can set on a user control. This style is only applied in the designer and is not used at runtime.

You use it like this:

<UserControl ... d:DesignStyle="{StaticResource MyDesignStyle}" /> 

Or like this:

<UserControl ...>     <d:DesignerProperties.DesignStyle>         <Style TargetType="UserControl">...</Style>     </d:DesignerProperties.DesignStyle> </UserControl> 

Note however that any value set on the Style property (the one used at runtime) will also override the DesignStyle in the designer.

like image 156
Sebastien Pellizzari Avatar answered Sep 21 '22 03:09

Sebastien Pellizzari


I found that you can do one for yourself. Custom design-time attributes in Silverlight and WPF designer is a tutorial how to do it for both Silverlight and WPF.

like image 29
Oybek Avatar answered Sep 25 '22 03:09

Oybek