【问题标题】:dynamic resource in resource dictionary资源字典中的动态资源
【发布时间】:2011-04-13 13:45:43
【问题描述】:

我创建了一个资源字典

<ResourceDictionary x:Class="RPK.WindowsResources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:RPK.ViewModel"
    xmlns:vw="clr-namespace:RPK.View"
    xmlns:Converter="clr-namespace:RPK.Common">

    <sys:String x:Key="Key_Combo_Big_Width">200</sys:String>

<Style x:Key="ComboBig">
        <Setter Property="Control.Width" Value="{DynamicResource ResourceKey=Key_Combo_Big_Width}">
        </Setter>
        <Setter Property="Control.Height" Value="25"></Setter>
        <Setter Property="Control.VerticalAlignment" Value="Center"></Setter>
    </Style>
</ResourceDictionary>

我已将此作为合并字典应用到我的 app.xaml 中

在我的 window1.xaml 中,我将此样式应用为

<ComboBox Name="Combo1" Style="{StaticResource ComboBig}"/>

运行代码时出现此错误

'200' is not a valid value for property 'Width'

正确的方法是什么?

【问题讨论】:

    标签: wpf .net-3.5


    【解决方案1】:

    Width 属性是双精度的,因此如果要为其分配一个特定类型的资源值,则需要使用双精度资源。

        <sys:Double x:Key="Key_Combo_Big_Width">200</sys:Double>
    
        <Style x:Key="ComboBig">
            <Setter Property="Control.Width" Value="{DynamicResource Key_Combo_Big_Width}">
            </Setter>
            <Setter Property="Control.Height" Value="25"></Setter>
            <Setter Property="Control.VerticalAlignment" Value="Center"></Setter>
        </Style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      相关资源
      最近更新 更多