WPF 资源中的整数值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4185732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:19:28  来源:igfitidea点击:

An integer value in WPF Resources?

wpfwpf-controls

提问by serhio

Is that possible to set an integer value in WPF control Resources?!

可以在 WPF 控件资源中设置整数值吗?!

<UserControl.Resources>

    <SolidColorBrush x:Key="MyLineBrush" Color="LightGreen" />

    ??? <Integer x:Key="MyStrokeThickness" Value="2" /> ???


    <Style TargetType="local:MyLine" x:Key="MyLineStyleKey">    

        <Setter Property="Stroke" 
            Value="{DynamicResource MyLineBrush}"/>

        <Setter Property="StrokeThickness" 
            Value="{DynamicResource MyStrokeThickness}"/>

    </Style>

In order to modify dynamically the MyLineBrushand MyStrokeThicknessvalues...

为了动态修改MyLineBrushMyStrokeThickness值...

回答by Steve Greatrex

To make that declaration you need to import the Systemnamespace:

要进行该声明,您需要导入System命名空间:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

...

...

<sys:Int32 x:Key="MyValue">1234</sys:Int32>

Note: you will need to use a Doublefor most WPF properties instead of an Int32

注意:Double对于大多数 WPF 属性,您需要使用 a而不是Int32

回答by Sathya Ram

For StrokeThicknessit should be

对于StrokeThickness应该是

<system:Double x:Key="ThemeIconStrokeThickness">1</system:Double>