CrazyTn
CrazyTn

Reputation: 13

Sub classing all WPF base controls

Instead of using all the base wpf controls such as Label, TextBox, Grid, ect. I want to create a sub class of all these base controls and use the sub class.

e.g. public class MyTextBox : TextBox {}

They would be dummy classes for now, but it leaves room to be expandable in-case I need to in the future. Is this recommended or is it unnecessary?

Upvotes: 1

Views: 176

Answers (5)

Berryl
Berryl

Reputation: 12863

It sounds unnecessary, unproductive, and definitely not recommended!

Upvotes: 1

Michael Detras
Michael Detras

Reputation: 211

I think this is unnecessary. We can easily override the look and feel of a control using styles. In case you want to add properties, you can use attached properties.

Upvotes: 0

Brian Ensink
Brian Ensink

Reputation: 11218

If for some reason you need a subclass in the future it will be much easier to simply create it then than it to do lots of unnecessary work now.

Upvotes: 0

Steve Ellinger
Steve Ellinger

Reputation: 3973

This is a text-book definition of yagni

Upvotes: 4

slugster
slugster

Reputation: 49965

This sort of approach tends to be overkill. Where it does have its uses is when you know you will need to change the base UI controls at some point in the future. So if you were using a third party control suite then you might look at this approach, but you wouldn't want to do it with the MS controls as they are baked into the framework - you aren't going to change those!

Another approach is to ensure you follow a pattern like MVVM - this ensures that you have a UI that is nicely separated from your working code, and you can change controls with the minimum impact.

Upvotes: 0

Related Questions