XAML:以下符号之间的功能差异是什么?
XAML:以下符号之间的功能差异是什么?
我有什么理由不应该使用第一种属性方法吗?
<Setter Property="Shape.Stroke" TargetName="circle" Value="#FF3C7FB1"/>
<Setter Property="Shape.Stroke" TargetName="arrow">
<Setter.Value>
<SolidColorBrush>#FF222222</SolidColorBrush>
</Setter.Value>
</Setter>
所以我记得在声誉足够高后添加标签:
标签:扩展
编辑0:我使用默认模板来创建自定义控件,并注意到后者的布局是微软的做法。这是为了加快解析速度还是只是按照惯例?
编辑1:我发现转换器在使用前一种符号时投入使用,所以我想我的问题变成:这是一个性能问题吗?如果是的话,是否有任何基准?
XAML: What is the functional difference between the following notations?
Is there any reason I shouldn't use the first method for properties?
<Setter Property="Shape.Stroke" TargetName="circle" Value="#FF3C7FB1"/>
<Setter Property="Shape.Stroke" TargetName="arrow">
<Setter.Value>
<SolidColorBrush>#FF222222</SolidColorBrush>
</Setter.Value>
</Setter>
So I remember to add tags after reputation is high enough:
Tag: Expanded
EDIT 0: I am using the default templates to create custom controls and noticed the latter layout is how Microsoft does it. Is this to expedite parsing or simply by convention?
EDIT 1: I gather that the converters are brought into service when using the former notation, so I guess my question becomes: Is it a performance concern and, if so, are there any benchmarks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些确实是等价的符号。第一个较短,因为 WPF 隐式使用值转换器来转换给定的字符串。第二个是显式的、更灵活、更详细,但如果您需要设置也在 XAML 中定义的复杂值,则可能是最佳选择。
不应该是性能问题,除非您每秒调用设置器一百万次。
Those are equivalent notations really. The first one is shorter, because WPF uses a value converter implicitly to convert the given string. The second one is explicit, more flexible, more verbose, but could be the best choice in case if you need to set a complex value, that you also define in XAML.
Shouldn't be a performance concern, unless you're calling the setter million times a second.