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...
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With