質問

私は、ListView項目にHashSetのをバインドしようとしています。私はここに私のコードを文書化してきます:

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}

誰もがそれを達成する方法ティップスで私を助けることができますか?どうもありがとう!

乾杯

役に立ちましたか?

解決

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

あなたがそれをやった後は、あなたがサンプルコードの一番下にあなたのコメントがそれを記述する方法と似ListViewの各列のためのバインディングを設定する必要があります。

他のヒント

<ストライキ>この例 には、XMLデータにバインドソースは、しかし、あなたはあなたのニーズに適合させることができる必要があります。

また、リストビューここのMSDNドキュメントを参照してください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top