使用此声明有什么区别(或优点):
Style x:Key="{x:Type DataGridCell}" targettype="{x:Type DataGridCell}"
省略x:Key属性?
我认为WPF将密钥分配给相同的x:类型在引擎盖下.
解决方法
Style.TargetType
的MSDN文档证实您的怀疑:
Setting the targettype property to the TextBlock type without setting an x:Key implicitly sets the x:Key to {x:Type TextBlock}. This also means that if you give the above Style an x:Key value of anything other than {x:Type TextBlock},the Style would not be applied to all TextBlock elements automatically. Instead,you need to apply the style to the TextBlock elements explicitly.
如果一个样式的资源字典键是一个类型,该样式将被用作该类型的所有实例的默认样式,该类型不会明确指定样式.由于通常提供目标类型,省略密钥的语法只是定义默认样式的快捷方式.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。