WPF Management Inheritance

I read the following sentence in the blog :

The first WPF rule:
Avoid inheritance management.

I have seen similar things in other places. However, I do not understand the logic.

Also, here I see suggestions in StackOverflow that include the inheritance of WPF controls (e.g. answers to my previous question).

I would like to understand why (and if) inheritance of management should be avoided.

+7
inheritance wpf
source share
2 answers

WPF controls are "carefree." In other words, their appearance is separate from their behavior. More often than not, you really want to customize the look, not the behavior. Unlike the Winforms world, this does not require you to inherit a new control and redefine the visualization. Instead, you set some properties of the control, resorting to overriding the template itself if you cannot get the look you want from other properties.

Note that β€œavoid” means exactly that. Avoid inheritance if you can. In cases where you need to change behavior, inheritance may be the best option.

+8
source share

The blog post also says:

"With styles, templates, decorators, and attached properties and behavior, you can accomplish most of the things that you had a roll of new control for.

It's right. However, if that were the case, the wpftoolkit command would not make their DataGrid a subclass of MultiSelector .

Judge each case separately, I would say. Also check out this answer.

+4
source share

All Articles