2

C#に2つの同様のクラスがあります

public class Property
{
    public string version;               
    public string CCodeName { get; set; }
    public string CDoc { get; set; }
    public string ShortName { get; set; }
}

public class PropertyFieldsInExcel
{
    public string ShortNames { get; set; }
    public string CNames { get; set; }
    public string CDoc { get; set; }
    public string Version { get; set; }        
}   

この後、2 つのリストを作成しました。

static List<PropertyFieldsInExcel> listA = new List<PropertyFieldsInExcel>();
public List<Property> listB = new List<Property>();

ここで、これら 2 つのリストを双方向でバインドしたいと考えています。listA同様に、対応する要素で何かが変更されるたびに、listB更新する必要があります。

if と同様、listA[i].ShortName = "abc"thenlistB[i].ShortNameも同じ値でなければなりません。 listA.Add()トリガーする必要がlistB.Add()あり、その逆も同様です。

ありがとうございました!

4

2 に答える 2

2

@Amir が言ったように、INotifyPropertyChanged クラスを実装する必要があります。

あなたのケースは、INotifyPropertyChangedからの正確な例です

この例を試してみてください。

于 2016-06-02T09:56:02.087 に答える
-1

System.ComponentModel.INotifyPropertyChangedクラスに -Interface を実装し、PropertyChangedイベント ハンドラーを使用してクラスに対応する変更を加えます。System.Collections.ObjectModel.ObservableCollection<>リストの代わりに使用します。

于 2016-06-02T07:55:03.477 に答える