I am creating a custom control in WPF, it is the highly unoriginal example of a stock ticker that I am deriving from the Control type. My question is: Are there any recommnded design patterns for controls themselves (as opposed to the app)? I am using MVVM for the application as a whole but just wandered if it is good or bad practice to use such a design pattern with the control itself.
My reasons for thinking of using MVVM for the control is that:
- It is a relatively complex control, in that it has a graphing ability and Dependency Properties of Midprice, Average etc etc
- To have a ViewMOdel as part of it would make unit testing it easier (or even possible)
- Makes the entire coding process easier, especially as I have a bespoke ObservableCollection of point types.
Any thought on the matter would be brilliant. I just don’t know if this is good practice or not.
Many thanks
If the control itself is self contained and sufficiently complex to be called a view by itself, I would go with the approach of creating a separate viewmodel for the control itself, like you suggest. Otherwise, I’d just let it live in the view that it’s hosted in.