Reputation: 4625
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:
What approach would be the best one? Or if you know any other approaches let me know.
Upvotes: 1
Views: 571
Reputation: 20746
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.
Upvotes: 4
Reputation: 982
Option 3... Put a facade of the 3rd-party control on your custom control that indirects to a private instance of the 3rd-party control. Try looking in the disassembly of the 3rd-party control (using Reflector or similar) for interfaces you could implement to assist with the building of the facade.
Upvotes: 1
Reputation: 49978
I would go with option 3. This would allow you to add additional features to the 3rd party control without needing to update it (option 2). This would be useful if the 3rd party provider updates there solution. You wouldnt need to re-add your changes. I wouldnt go with option 4 if you dont need your control to derive from content control. It might be confusing to future developers. So option 3 seems the best.
Upvotes: 1