Xaser
Xaser

Reputation: 2146

Base class for custom controls

I know that there is plenty of material on this question, but there are also many contradictory answers without any further explanation, leaving me in alot of confusion.

I'm about to start a bigger MVVM WPF project, which will also contain some custom controls (video editor like time slider bar, color-wheels etc.)

To learn implementing custom controls, I thought I'd first try to create a simple color picker wheel. The challenging part obviously is to render the color selection circle. From what I read on MSDN, I would start of by inheriting from Control and once render the background for the color selection circle.

This project however inherits from Usercontrol instead of Control but also renders the background once as a bitmap.

In this case, which is the correct base class to inherit from?

Upvotes: 2

Views: 702

Answers (1)

Stígandr
Stígandr

Reputation: 2902

Inherhit from Control or ItemsControl when you intend to create controls.

You use UserControl or Page as a baseclass when you creaate what we call a view(Your screens). There is an existing template for adding a customcontrol to your projects under the WPF items folder(when adding new items), this template will create the basics of what you need, an almost empty controltemplate in Themes/Generic.xaml and a class derived from control with the needed initialization.

Note if you want to extend functionality of existing controls you can subclass them as well, but I would rather create behaviours when possible(nice easy clean, and reusable).

Hope it helps,

Cheers,

Stian

Upvotes: 1

Related Questions