开发者

dynamic resource in resource dictionary

开发者 https://www.devze.com 2023-02-25 10:51 出处:网络
I have a created a resource dictionary as <ResourceDictionary x:Class=\"RPK.WindowsResources\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"

I have a created a resource dictionary as

<ResourceDictionary x:Class="RPK.WindowsResources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xm开发者_如何学Clns: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>

I have applied this as a merged dictionary in my app.xaml

In my window1.xaml, I have applied this style as

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

When I run the code I get this error

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

What is the correct way?


The Width property is a double so if you're going to assign it a specifically typed resource value you need to use a double resource.

    <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>
0

精彩评论

暂无评论...
验证码 换一张
取 消