来自几个表的MVVM模式绑定

时间:2014-09-15 12:50:34

标签: c# wpf mvvm data-binding binding

我正在创建一个继承ObservableCollection TestCollection的新类,如下所示:

public class TestCollectionList : ObservableCollection<TestCollectionList.TestCollection>
    {
        public TestCollectionList() : base()
        {
            Add(new TestCollection(D98DetailsCollection.PMID, D98EquipementsCollection.Libelle, D98DetailsCollection.Numéro, D98DetailsCollection.OTM, D98DetailsCollection.Work_Order, D98EquipementsCollection.Libelle, ResultatCollection.Groupe_D_alerte, D98DetailsCollection.Discipline, D98DetailsCollection.Discipline));
        }
        public class TestCollection
        {
            private string pmid;
            private string libellepmrq;
            private string ligne;
            private string otm;
            private string totm;
            private string libelleotm;
            private string ga;
            private string discipline;
            private string disciplinesubstituee;

            public TestCollection(string pmid, string libellepmrq, string ligne, string otm, string totm, string libelleotm, string ga, string discipline, string disciplinesubstituee)
            {
                this.pmid = pmid;
                this.libellepmrq = libellepmrq;
                this.ligne = ligne;
                this.otm = otm;
                this.totm = totm;
                this.libelleotm = libelleotm;
                this.ga = ga;
                this.discipline = discipline;
                this.disciplinesubstituee = disciplinesubstituee;
            }

            public string Pmid
            {
                get { return pmid; }
                set { pmid = value; }
            }
            public string Libellepmrq
            {
                get { return libellepmrq; }
                set { libellepmrq = value; }
            }
            public string Ligne
            {
                get { return ligne; }
                set { ligne = value; }
            }
            public string Otm
            {
                get { return otm; }
                set { otm = value; }
            }
            public string Totm
            {
                get { return totm; }
                set { totm = value; }
            }
            public string Libelleotm
            {
                get { return libelleotm; }
                set { libelleotm = value; }
            }
            public string Ga
            {
                get { return ga; }
                set { ga = value; }
            }
            public string Discipline
            {
                get { return discipline; }
                set { discipline = value; }
            }
            public string Disciplinesubstituee
            {
                get { return disciplinesubstituee; }
                set { disciplinesubstituee = value; }
            }

        }
    }

当我尝试创建集合时,对于每个值,我都有同样的错误Cannot access non-static property in static context

public TestCollectionList() : base()
        {
            Add(new TestCollection(D98DetailsCollection.PMID, D98EquipementsCollection.Libelle, D98DetailsCollection.Numéro, D98DetailsCollection.OTM, D98DetailsCollection.Work_Order, D98EquipementsCollection.Libelle, ResultatCollection.Groupe_D_alerte, D98DetailsCollection.Discipline, D98DetailsCollection.Discipline));
        }

这些是其他ObservableCollections,如D98DetailsCollection等:

class ViewModel:INotifyPropertyChanged
{
    private BDDInterneEntities _BDDInterneEntities;

    public ViewModel()
    {
        _BDDInterneEntities = new BDDInterneEntities();
        ResultatCollection = new ObservableCollection<Resultat>(_BDDInterneEntities.Resultat);
        D98EquipementsCollection = new ObservableCollection<D98Equipements>(_BDDInterneEntities.D98Equipements);
        D98DetailsCollection = new ObservableCollection<D98Details>(_BDDInterneEntities.D98Details);
        D675Collection = new ObservableCollection<D675>(_BDDInterneEntities.D675);
        cmpc = new CompositeCollection();

        CollectionContainer cc1 = new CollectionContainer();
        CollectionContainer cc2 = new CollectionContainer();
        CollectionContainer cc3 = new CollectionContainer();
        CollectionContainer cc4 = new CollectionContainer();
        cc1.Collection = ResultatCollection;
        cc2.Collection = D98EquipementsCollection;
        cc3.Collection = D98DetailsCollection;
        cc4.Collection = D675Collection;
        cmpc.Add(cc1);
        cmpc.Add(cc2);
        cmpc.Add(cc3);
        cmpc.Add(cc4);



    }
    public ObservableCollection<Resultat> ResultatCollection { get; set; }
    public ObservableCollection<D98Equipements> D98EquipementsCollection { get; set; }
    public ObservableCollection<D98Details> D98DetailsCollection { get; set; }
    public ObservableCollection<D675> D675Collection { get; set; }
    public CompositeCollection cmpc {get; set; }

    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string property)
    {
        if(PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }

    }
}

我想要的是创建一个包含来自多个表的数据的ObservableCollection。我是初学者,所以我对使用何时以及为何使用感到非常尴尬。

我不确定我是否可以使用ObservableCollection中的数据并将其发送给另一个,或者如果我每次都必须调用DbSet:Add(new TestCollection(DbSet<D98Details> ..........

如果有人有勇气帮助我。我已经阅读了很多教程,例如http://msdn.microsoft.com/fr-fr/library/ms752347(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/ff798384.aspx,但即使我理解了这个概念,我也很难将它应用到我的案例中。

我也可以更新我的帖子如果缺少某些信息。

提前致谢。

0 个答案:

没有答案