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
An integer value in WPF Resources?
提问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 MyLineBrush
and MyStrokeThickness
values...
为了动态修改MyLineBrush
和MyStrokeThickness
值...
回答by Steve Greatrex
To make that declaration you need to import the System
namespace:
要进行该声明,您需要导入System
命名空间:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
...
...
<sys:Int32 x:Key="MyValue">1234</sys:Int32>
Note: you will need to use a Double
for 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>