0

After this: Acess to a DataGrid through C# code and manipulate data inside the DataGrid I decided that i should deserialize my XML data and use it that way because i need basic CRUD manipulation in my application.

I already have my xml data class (using XSD tool, you can find the class here -> http://pastebin.com/6GWFAem6) and have my data deserialized, problem is:

  1. I need a TabControl with as many tabs as Semestre in my xml, each tab will have GPASemestre.Nome header.

  2. Inside each tab i need a DataGrid with Cadeiras of that specific Semestre.

  3. I need to be able to CRUD data in the DataGrid and the tabs.

Questions:

  1. To solve all of this what do you think is best? Creating everything (tabs + datagrid) and make the necessary binds (which i don't really know what they will be) / populate the DataGrid somehow, in C# only? Or there is a way to simplify code in C# using XAML?
  2. Cadeiras are stored in arrays so, each time i add a new one, i need to create a new array (or create a new array with more spaces and manage it), i already saw some questions here where ppl used List's but where having troubles with it, is it possible to use a list or not? If so, what do i have to change in the XSD auto generated class?

Thanks in advance!

Community
  • 1
  • 1
vvolkgang
  • 471
  • 8
  • 26

1 Answers1

0

I would suggest the use of data-binding and data-templating (read those if you have not yet done so) for as much as possible, for that to work well the auto-generated classes need to be adjusted to support it.

The first step is implementing INotifyPropertyChanged in all the properties which are not collections so that if the property is changed the UI will update automatically. Only use arrays for deserialisation at best, after that copy the elements to a property which is of type ObservableCollection<T>, or any other collection which implements INotifyCollectionChanged so that the grids update when a new item is added to the collection and never touch the arrays again.

You could also make the Array property "virtual" (has no backing field, just manipulates on get & set), e.g.:

//The property & field used for binding and editing
private readonly ObservableCollection<GPASemestre> _ObservableSemestre = new ObservableCollection<GPASemestre>();
public ObservableCollection<GPASemestre> ObservableSemestre { get { return _ObservableSemestre; } }

//The property used for serialisation/deserialisation
public GPASemestre[] Semestre
{
    get
    {
        return ObservableSemestre.ToArray();
    }
    set
    {
        ObservableSemestre.Clear();
        foreach (var item in value)
        {
            ObservableSemestre.Add(item);
        }
    }
}
H.B.
  • 166,899
  • 29
  • 327
  • 400
  • About the ObservableCollection, what you are saying is having one class for deserialization and almost the same class for run-time with the ObservableCollection proprieties instead of arrays? Isn't that a lot of processing and memory waste? Because, with your 2nd solution, i could use the same deserialized class for all my data storage and manipulation. – vvolkgang Aug 09 '11 at 03:35
  • @NoSila: It can be the same class, but i do not know if that is good practise, do you need to serialize and deserialize that often? – H.B. Aug 09 '11 at 10:43
  • No, i just need to deserialize when app starts and serialize when app finishes OR if user wants to save... – vvolkgang Aug 10 '11 at 17:05
  • FINALLY, i'm starting to understand all the data binding / data templating with CLR objects, i'm going to separate the classes, one for deserialization only and another to keep the run-time data, it makes things cleaner (plus, if you serialize the class with that code you would get the ObservableSemestre tag in there). Thanks a lot for your help ;) – vvolkgang Aug 13 '11 at 21:08