【问题标题】:WPF GridLength in XAMLXAML 中的 WPF GridLength
【发布时间】:2012-12-03 20:28:08
【问题描述】:

我正在尝试在 Common.xaml 中定义一个常见的 Width 资源,该资源将由不同的控件共享,如下所示:

<GridLength x:Key="CommonWidth">20</GridLength>

然后我在 ButtonStyle.xaml 中定义的 Button 样式中使用它

<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Width" Value="{DynamicResource CommonWidth}"/>
    ....
</Style>

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

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

有人知道我做错了什么吗?提前致谢。

【问题讨论】:

    标签: wpf xaml resourcedictionary gridlength


    【解决方案1】:

    注意Button.Width 不是GridLength 类型。在Grid.GridLength 中,您可以将值指定为固定、自动或星号。它仅用于Grid 中的行、列的大小。

    Button.Width 的类型为 double。也就是说,如果你想使用一个资源来设置它,你需要一个像

    这样的资源
    <sys:Double x:Key="Height">200</sys:Double>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-06
      • 2013-07-03
      • 1970-01-01
      • 2010-11-28
      • 1970-01-01
      • 2021-09-10
      • 2010-10-01
      • 1970-01-01
      相关资源
      最近更新 更多