An integer value in WPF Resources?

WpfWpf Controls

Wpf Problem Overview


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

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

Wpf Solutions


Solution 1 - Wpf

To make that declaration you need to import the System namespace:

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

Solution 2 - Wpf

For StrokeThickness it should be

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

Solution 3 - Wpf

Looks like the Assembly has changed updated for 2020:

xmlns:sys="clr-namespace:System;assembly=System.Runtime"

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionserhioView Question on Stackoverflow
Solution 1 - WpfSteve GreatrexView Answer on Stackoverflow
Solution 2 - WpfSathya RamView Answer on Stackoverflow
Solution 3 - WpfAndy BrahamView Answer on Stackoverflow