Best practice: create user control or implement using behavior?

With the current WPF functions, many of the user-defined functions that I would normally use to implement in a user control can be just as easily handled by behavior and attached properties.

For example, a watermarked TextBox can be processed using Behavior , which adds the attached property β€œWatermarkText” and sets a custom VisualState .

Can someone clarify best practices, performance issues, or criteria in order to implement additional features like Behavior compared to a custom control?

The obvious thing is that Behavior can be applied to multiple controls. But in the spirit of code reuse, isn't it better to always be able to reuse bahaviour? Even if only for derived controls.

+4
source share
1 answer

If you're a Blend designer, you can easily mix and match behavior. Of course, a custom control can also be used in Blend, but designers can only change properties and style.

As far as I know, Blend teams designed the behavior to better facilitate the "development" of the non-developer.

Thus, the behavior has some advantages when working in Blend.

+3
source

Source: https://habr.com/ru/post/1494485/


All Articles