Strict vs handy syntax for some properties' values in XAML
There are a bunch of properties to which you could provide a value in several ways. For example:
- Style.TargetType: "ns:Typ开发者_运维问答eName" vs "{x:Type ns:TypeName}"
- Button.Command: "ns:TypeName.StaticPropertyName" vs "{x:Static ns:TypeName.StaticPropertyName}"
- You name it.
The question is: are there any drawbacks which comes along with handy syntax?
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".
精彩评论