开发者

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:

  1. Style.TargetType: "ns:Typ开发者_运维问答eName" 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜