wbsat
wbsat

Reputation: 61

Best way to store data for various ui elemnts on screen

I am developing a diagramming tool where I drag and drop controls to the diagramming surface,just like VS or visio or paint.

Each control/element ,dropped on the surface, will present a context menu "properties" when right clicked. The "properties" dialog will display a set of data relevant to each element/control.

My question is how best to store/load this non UI data,attached to each element/control on the surface.

for example I create elements LED1,breaker 1,connector 1 in design mode.i will to have store
different set of data for each of them.

storage logic will be like this

   for all elements on diagram
    1. input element id,element type.
    2. store data for that element ID.  

When the diagram i created, is run as a application, the appropriate data has to be retrieved for each for these elements from storage by the loader.

loader logic may go like this

for all elements on diagram

  1. detect element id and element type
  2. get data for the above id.

I thought xml of a resource. but my manager didn't seem enthusiastic.

I was wondering how the most experienced/proficient wpf developers will go about this.

Upvotes: 1

Views: 143

Answers (3)

kenny
kenny

Reputation: 22334

I don't think XML is a bad way to go. If fact it's the way Office sub-elements are stored. Take a look at Microsoft's XPS Packaging format and APIs. (MSDN)

Upvotes: 0

dowhilefor
dowhilefor

Reputation: 11051

I might not understand your question completely. But we store our business data in a custom binary format, which is basically just the property value dump of the tree of our business data into a database. Depending on your requirements you need to make sure to handle change in file format (different versions) and properly handle cross referencing. Each object is dumped on its own, and a second pass makes sure that the cross references are resolved.

Besides that i would make it as easy as possible:

Model classes for each type of diagram element, which itself are only storing the business relevant data (i would consider position and size in a diagram application as business data). These models could be made Serializable. Manager classes to operate on these models, with undo redo, view model creation etc. And view models that wrap these models and store additional stuff like commands, ui information (is selected, is expanded etc.).

For the view i strongly advice to create a custom ItemsControl with a virtualizing canvas.

Upvotes: 1

Nikita B
Nikita B

Reputation: 3333

I think it depends on scale. If you have thousands of objects, which state you need to save/load you d better set up a database, where you will store your data. If its just a few dozens of objects - XmlSerialization is the most obvious choice.

Upvotes: 0

Related Questions