Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF control inheritance

I've read in a blog the following sentence:

The first rule of WPF:
Avoid control inheritance.

I've seen similar things in other places as well. However, I fail to understand the logic.

Moreover, I see suggestions here in StackOverflow that involves inheriting WPF controls (see the replies to my previous question for example).

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

like image 392
Elad Avatar asked Aug 04 '09 08:08

Elad


1 Answers

WPF controls are "lookless". In other words, their look is separated from their behavior. More often than not, you actually want to customize the look - not the behavior. Unlike the world of Winforms, this does not require you to inherit a new control and override rendering logic. Instead, you set some properties on the control, resorting to overriding the template itself if you can't get the look you want from other properties.

Note that "avoid" means just that. Avoid inheritance if you can. In cases where you need to modify behavior, inheritance may well be the best option.

like image 111
Kent Boogaart Avatar answered Sep 26 '22 02:09

Kent Boogaart