Is there a way in WPF to specify a width/height as a resource, so that it can be reused in several styles for e.g. margin/padding?
A:
Yes it is and you use it as other Resources and fetch then using StaticResource see some examples here.
Filip Ekberg
2010-02-17 10:16:59
Sorry Filip, I'm not seeing where a width/height is set and used as a resource in that example?
devdigital
2010-02-17 11:22:04
There are examples on how you use it in other contexts, try them, read between the lines and explore.
Filip Ekberg
2010-02-17 12:08:00
+2
A:
Sure.
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<sys:Double x:Key="Height">200</sys:Double>
<sys:Double x:Key="Width">200</sys:Double>
</Page.Resources>
<Grid>
<Rectangle
Height="{StaticResource Height}"
Width="{StaticResource Width}"
Fill="Blue"/>
</Grid>
</Page>
Robert Rossney
2010-02-17 11:46:40