tags:

views:

35

answers:

1

Hi there.

There are a bunch of properties to which you could provide a value in several ways. For example:

  1. Style.TargetType: "ns:TypeName" vs "{x:Type ns:TypeName}"
  2. Button.Command: "ns:TypeName.StaticPropertyName" vs "{x:Static ns:TypeName.StaticPropertyName}"
  3. You name it.

The question is: are there any drawbacks which comes along with handy syntax?

+1  A: 

I think the main drawback is that you might sometimes use the same shorter syntax on a property that is of a less specific type, thus no auto-conversion occurs. You could be scratching your head for a while before realizing that it's due to your value being treated as a string. In other words, the translation of these convenient short-hands is contextual.

Here's a very contrived example:

<Button Command="local:Command.ExitCommand" Tag="local:Command.ExitCommand">Exit</Button>

In this example, the Command property will correctly resolve the ICommand instance, but the Tag property will be set to the text "local:Command.ExitCommand".

HTH,
Kent

Kent Boogaart
So you suggest to write `{x:Type ...}`, `{x:Static }` and so on regardless its necessity?What about enums? Do you suggest `Visible` or `{x:Static Visibility.Visible}`?
archimed7592
I am merely suggesting you be aware of this issue. The shorthand version exists for a reason - it is tedious and verbose without it. But just be aware of what's going on behind the scenes to make it work.
Kent Boogaart