WPF中XAML中的GridLength

3
我正在尝试在Common.xaml中定义一个通用的Width资源,该资源将被不同的控件共享,如下所示:
<GridLength x:Key="CommonWidth">20</GridLength>

我会将其翻译为:我随后在ButtonStyle.xaml中定义的按钮样式中使用它。
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Width" Value="{DynamicResource CommonWidth}"/>
    ....
</Style>

在App.xaml中的ResourceDictionary定义中,Common.xaml在ButtonStyle.xaml之前被包含。当我运行应用程序(.Net3.5 SP1上),我得到了以下异常:

'20' is not a valid value for property 'Width'.

有人有任何想法我做错了什么吗?提前感谢。
1个回答

2
请注意,Button.Width不是GridLength类型。在Grid.GridLength中,您可以将值指定为固定、自动或星号。它仅用于Grid中行和列的大小。 Button.Widthdouble类型。如果您想使用资源设置它,那么您需要像这样的资源:
<sys:Double x:Key="Height">200</sys:Double>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接