I'm trying to define a common Width resource in Common.xaml which will be shared by different controls, like following:
<GridLength x:Key="CommonWidth">20</GridLength>
I then use it in a Button style defined in ButtonStyle.xaml
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Width" Value="{DynamicResource CommonWidth}"/>
....
</Style>
Common.xaml is included before ButtonStyle.xaml in the ResourceDictionary definition in App.xaml. When I ran the application (on .Net3.5 SP1), I got the following exception:
'20' is not a valid value for property 'Width'.
Anyone has any ideas of what I have done wrong? Thanks in advance.
Note that
Button.Width
is not of typeGridLength
. InGrid.GridLength
you can specify the value as fixed, auto or star. It is only used for size of rows, columns inGrid
.Button.Width
is of typedouble
. That is if you want to set it using a resource you need a resource like