交互性.行为与附加属性

发布于 2024-08-22 09:11:52 字数 53 浏览 8 评论 0原文

我试图找出这些方法之间的一些差异。是否存在使用行为但无法使​​用附加属性完成相同功能的情况?

I'm trying to find some differences between these approaches. Is there any situation where behaviors are used and the same functionality could not be done with attached properties?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

柠檬色的秋千 2024-08-29 09:11:52

不。行为基本上只是附加属性之上的更好的抽象。

通过使用 Behavior,您可以直接访问 AssociatedObject,并能够在运行时轻松附加和分离行为。

您可以使用附加属性来做到这一点,但这需要添加大量额外的管道。

No. Behaviors are basically just a much nicer abstraction on top of attached properties.

By using Behavior<T>, you gain access to the AssociatedObject directly, as well as the ability to attach and detach the behavior, easily, at runtime.

You could do this with attached properties, but it would require adding a lot of extra plumbing.

末骤雨初歇 2024-08-29 09:11:52

我倾向于使用行为来添加可进行可见更改的功能。而我使用附加属性向对象添加附加信息,随后由其他对象使用。

例如,Grid.Row 是一个很好的附加属性,因为它由网格而不是目标使用。另一方面,自动更正会产生良好的行为,因为这将对对象进行可见的更改。

I tend to use Behaviors to add functionality which makes visible changes. Whereas I use attached properties to add additional information to an object which is subsequently used by other objects.

E.g. Grid.Row makes a good attached property, as it's used by the Grid and not the target. On the other hand, AutoCorrect would make a good behaviour, as this will make visible changes on the object.

空心空情空意 2024-08-29 09:11:52

行为基于附加属性。这意味着如果您找不到特定的行为 - 您可以根据 Blend 提供的行为框架或创建自己的 AP 编写自己的行为...

我一直认为行为是附加属性功能的重要证据。与他们一起你能得到令人难以置信的东西。

Behaviors are based on attached properties. That means if you can't find specific behavior - you write your own, either based on behaviors framework provided by Blend or by creating your own AP...

I always thought that behaviors are great evidence of attached properties power. Just incredible what you can get with them.

绮烟 2024-08-29 09:11:52

这不是答案。但我能找到关于这个主题的最好解释
https://web.archive.org/web/20180208143035/http://briannoyesblog.azurewebsites.net/2012/12/20/attached-behaviors-vs-attached-properties-vs -blend-behaviors/

Brian Noyes 在他的文章中清楚地描述了每个概念之间的差异。

This is not the answer. But the best explanation I can find on this topic
https://web.archive.org/web/20180208143035/http://briannoyesblog.azurewebsites.net/2012/12/20/attached-behaviors-vs-attached-properties-vs-blend-behaviors/

Brian Noyes in his articles clearly describes the differences between each of the concepts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文