Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WPF how do we define Duration as a resource?

Tags:

wpf

xaml

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.

like image 990
Zoman Avatar asked Jul 03 '10 08:07

Zoman


People also ask

What is resource 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 is static resource in WPF?

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.

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.

What is resource dictionary?

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.


1 Answers

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

like image 122
codekaizen Avatar answered Oct 13 '22 13:10

codekaizen