Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An integer value in WPF Resources?

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

like image 951
serhio Avatar asked Nov 15 '10 15:11

serhio


People also ask

What are resources in WPF?

A resource is an object that can be reused in different places in your application. WPF supports different types of resources. These resources are primarily two types of resources: XAML resources and resource data files. Examples of XAML resources include brushes and styles.

What are dynamic resources in WPF?

Dynamic ResourceThe concept is the same as data binding in WPF if the value of the bound property is changed. So is the value on UI. Change XAML as follows: added a new button. Also, add 2 resources in the code behind.

What is resource in XAML?

A resource is an object that can be reused in different places in your app. Examples of resources include brushes and styles. This overview describes how to use resources in Extensible Application Markup Language (XAML). You can also create and access resources by using code.


1 Answers

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

like image 92
Steve Greatrex Avatar answered Sep 30 '22 18:09

Steve Greatrex