有什么区别
TargetType="{x:Type Button}"
和
TargetType="Button"
System.TypeXAML 设计器应用了将字符串值“Button”转换为 is的内置类型转换器Button,这使得看起来没有实际区别。
但是,应该练习使用显式类型规范使用x:Type.
需要显式Type规范是当我们继承Stylesusing时BasedOn,隐式字符串将Type不起作用。
例如
这会起作用
BasedOn="{StaticResource {x:Type Button}}"
但不是这个...
BasedOn="{StaticResource Button}"
就像这里它会尝试使用键“按钮”搜索资源。但是在x:Type规范中,正如我们已经明确指定的那样Button Type,静态资源的搜索将Style针对针对 a 的Button.