【发布时间】:2009-06-15 15:25:19
【问题描述】:
我正在尝试将 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}
谁能帮助我提示如何实现这一点?非常感谢!
干杯
【问题讨论】:
-
此外,除非您为 Addresses 类添加(或需要)IEqualityComparer,否则我会避免使用 HashSet 而不是更简单的集合,例如 List
。 -
但是HashSet不是更快吗?我实际上不需要任何特定的 HashSet 函数(“nice-to-have”唯一条目部分除外)..
标签: c# wpf inotifypropertychanged hashset