I know that C# isn’t C++ in terms that it restricts you from deriving from multiple classes, but what are the ways to overcome it when developing a WPF application.
In my scenario I have a third party control which is a slider, it doesn’t derive from content control, hence doesn’t have a content property. However I need to have that property.
Several solution came to my mind:
- Derive from multiple classes (Not possible in C#)
- Add an attached property to the third party control
- Extend third party control and add a Content property and all other properties which are required for it to function.
- Encapsulate 3rd party control inside my custom control and derive from content control.
What approach would be the best one? Or if you know any other approaches let me know.
I vote for option 4. Composition seems to be a better option then inheritance in a long run. Later you will be able to replace you third-party control with something else without anybody from outside world knowing about the change. In other words you will encapsulate the dependency on the third-party control in your control.