tags:

views:

32

answers:

1

So I am currently creating a Paint-like application for sports. You will some "shapes" for each type of sport (balls/baskets in basketball, pucks/goals in hockey etc.).

Now my main problem is how I should go about designing these shapes. As I understand it there are mainly 3 options:

  • Custom Control with ControlTemplate
  • UserControl
  • POCO-Object (ViewModel) for property storage, DataTemplate for visual representation

I have the following requirements for the Shape-objects:

  • Should be easily serializable (to save as XML etc.)
  • Should be able to have adorners attached to them (for purposes of resizing etc.)
  • Should be extensible/modifiable (provide different visual styles for them etc.)
  • Should provide some default value mechanism for the properties

Which option would fit my requirements best?

A: 

Since you have a clear domain model (balls, pucks, etc) I would recommend modelling those as separate objects (ViewModels) and then use DataTemplates to style them visually. That way you have the most control over what gets serialized and you can version your visuals independently from your data model.

Serialization will be handled by your data model. The DataTemplates might use custom shapes (just derive from Shape) to do the actual rendering. Adorners work on any UIElements and if you use data binding to bind the relevant properties back to your ViewModels you have the requried data to serialize. As for the mechanism for default values just let the default constructor on your Ball and Puck class set the proper values (diameter, weight, etc)

Happy coding

jesperll