0

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?

Community
  • 1
  • 1
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208

1 Answers1

1

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

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185