0

HashSet を ListView アイテムにバインドしようとしています。私は自分のコードをここに文書化しました:

public class Person {
    public string Name { get; set; }
    public AddressList = new AddressList ();
}
public class AddressList : HashSet<Addresses>
{
    //
}
public class Addresses {
    public string Streetname { get; set; }
    public string City { get; set; }
}
public class PersonViewModel : INotifyPropertyChanged {
    private Person _person;

    public PersonViewModel(Person person)
    {
        _person= person; 
    }

    public string Name
    {
        get { return _person.Name; }
        set
        {
            _person.Name = value;
            OnPropertyChanged("Name");
        }
    }
    private void OnPropertyChanged(string property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }
}

 // This is how I add the DataContext: mainGrid.DataContext = _person //this is a PersonViewModel();
 // This is how I bind the DataObjects to the GUI Elements: <TextBox Name="TxtBoxName" Text="{Binding Path=.Name, Mode=TwoWay}"/>
 // How can I add in the same way a HashSet to a ListView Element in the WPF Gui? I tried something like {Binding Path=.Name, Mode=TwoWay}

それを達成するためのヒントを教えてくれる人はいますか?どうもありがとう!

乾杯

4

2 に答える 2

1

コレクションを にバインドするにはListView(さらに言えば任意ItemsControlの )、そのItemsSourceプロパティを設定する必要があります。AddressListコレクションがリストに表示したいものであると仮定すると、これはクラスのインスタンスにバインドする必要があります。

それが完了したらListView、サンプル コードの下部にあるコメントで説明されているように、 の各列のバインディングを設定する必要があります。

于 2009-06-15T16:49:48.837 に答える
0

この例は XML データ ソースにバインドしますが、必要に応じて調整できるはずです。

こちらの ListView に関する MSDN ドキュメントも参照してください。

于 2009-06-15T17:15:46.680 に答える