I have a duration (0:0:0.5) that I use in a number of animations and I would like to define this number at one place only. I can define a double for instance as
<Window.Resources>
<sys:Double x:Key="GridWidth">400</sys:Double>
</Window.Resources>
But not sure how a duration should be expressed as a resource. Thanks.
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.
Static Resource - Static resources are the resources which you cannot manipulate at runtime. The static resources are evaluated only once by the element which refers them during the loading of 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.
A resource dictionary is a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common.
<Window.Resources>
<Duration x:Key="aDuration">0:0:0.5</Duration>
</Window.Resources>
In general, you can look at the MSDN doc for the type to see if they give XAML syntax. In the case of WPF types, there usually is: http://msdn.microsoft.com/en-us/library/ms602372.aspx.
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