Interactivity.Behavior<T> vs attached properties

核能气质少年 提交于 2019-12-03 04:01:10

问题


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?


回答1:


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.




回答2:


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.




回答3:


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

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




回答4:


This is not the answer. But the best explanation I can find on this topic 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.



来源:https://stackoverflow.com/questions/2327554/interactivity-behaviort-vs-attached-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!