Do order of code in XAML effect its build relevance in WPF?

I asked a question earlier regarding

<Button Command="{StaticResource hwc}" CommandParameter="Hello" ...

in which to overcome my problem i was asked to switch the place of these two attributes i.e. CommandParameter should come first and Command` later. This way

<Button CommandParameter="Hello" Command="{StaticResource hwc}" ...

No doubt, this thing worked. But left a few questions in my mind.

  1. Do the order of attributes matter?
  2. Does this same principle apply to styles also. My seniors at job say styles should be written/defined in a file before they are used

I have a button designed

<Button Style="{StaticResource FooStyle}" ....

and the style is defined way down below after this button is declared

<Style x:Key="FooStyle" TargetType="{x:Type Path}" ...

Will this style be applied to that button even though it is declared after button is declared?

In code behind we cannot use a variable before its declaration, so does the same apply to XAML code also?


Yes indeed you need to define your Style above its usage if you are referring to it using StaticResource but in case you are referring it as a DynamicResource, the order does not matter. It gets resolved at run time.

<Button Style={DynamicResource FooStyle}...

Refer to this link for detailed description for the difference StaticResource vs DynamicResource

Need Your Help

Specifying the type of ArrayList's elements

c# .net generics

I thought that there was some way in .net 3.0 to give an array list a type so that it didnt just return Object's but I'm having trouble doing so. Is it possible? If so, how?

Can a function defined in a bookmarklet be called from a page-level script?

javascript permissions popup wrapper bookmarklet

I have a bookmarklet that needs to open a new window/tab. In order to avoid the popup blocker, I need to call the method directly in the bookmarklet ie: at the browser-level.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.