在TabController + DataGrid中使用反序列化的XML数据 [英] Use deserialized XML data in TabController + DataGrid

查看:229
本文介绍了在TabController + DataGrid中使用反序列化的XML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之后:通过C#代码访问DataGrid并处理DataGrid内的数据我决定,我应该反序列化我的XML数据并使用它,因为我需要在我的应用程序中进行基本的CRUD操作。

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.

我已经有了我的xml数据类(使用XSD工具,你可以在这里找到这个类 - > http://pastebin.com/6GWFAem6 ),并将我的数据反序列化,问题是:

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. 我需要一个TabControl,在我的xml中有几个选项卡作为Semestre,每个选项卡都将有GPASemestre.Nome标题。

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

一个具有特定Semestre的Cadeiras的DataGrid。

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

问题:


  1. 要解决所有这些你认为最好的?创建所有的东西(tab + datagrid)并进行必要的绑定(我不知道他们会是什么)/填充DataGrid不知何故,仅在C#中?或者有一种方法可以使用XAML简化C#中的代码?

  2. Cadeiras存储在数组中,所以每次添加一个新的数组时,我需要创建一个新的数组(或创建一个新的数组有更多的空间和管理它),我已经看到一些问题,在这里ppl使用列表,但在哪里有麻烦,是否可以使用一个列表?如果是这样,我必须在XSD自动生成的类中更改?

提前感谢!

推荐答案

我建议使用数据绑定数据模板(如果你还没有这样做),尽可能的,为了工作得很好,自动生成的类需要调整以支持它。

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.

第一步是实施 INotifyPropertyChanged 在所有不是集合的属性中,以便如果属性更改,UI将自动更新。只能使用数组进行反序列化,然后将元素复制到类型为 ObservableCollection< T> 或实现 INotifyCollectionChanged ,以便当新项目添加到集合中时,网格更新还可以再次触摸阵列。

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.

您还可以将Array属性virtual(没有后备字段,只是在get& set上操作),例如:

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);
        }
    }
}

这篇关于在TabController + DataGrid中使用反序列化的XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆