views:

74

answers:

2

Hi all,

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

A: 

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.

Per-Frode Pedersen
+1  A: 

1) Future Extensibility - Which I would say is the core when it comes to control development.
2) Good API Design - Create as much as Proof of Concepts.
3) Comes the pattern - If it is really big control. It is good to go with MVVM. But, learn to compromise it as well. Some times, we'll feel when it comes component development strict adherence to MVVM makes the control really complex.
4) Avoid over exposing of properties - Add properties as and when required. [Control feels it like an abuse, if properties are over exposed. ;)]
5) Make the control Lookless. Refer L for Lookless

General:
Try to make the control blendable from starting. It would help you to realize how good and usable from starting. Above all, it gives much satisfication and easy to track the completeness of the control.

When it comes to selecting a particular feature, think in two aspects:
1) Control's usability and
2) Control's Completeness.

Avatar