我正在将UltraTree
控件(版本10.3)绑定到自定义数据源,如下所示:
public void Populate(List<FilterDimension> data)
{
DataBindings.Clear();
DataSource = data;
Nodes[0].DataColumnSetResolved.NodeTextColumn = Nodes[0].DataColumnSetResolved.Columns["DisplayText"];
}
我的期望是,更改任何绑定的FilterDimension
对象的DisplayText属性将导致UltraTree
节点的文本更新。事实上,树中的文本不会更新,PropertyChanged
事件保持为null
,这表明UltraTree
甚至没有侦听此通知。如何让UltraTree
侦听FilterDimension
中的属性更改?
以下是FilterDimension
:的相关代码
internal class FilterDimension : INotifyPropertyChanged
{
private string _displayText = null;
private string _name = null;
private BindingList<string> _values = new BindingList<string>();
/// <summary>
/// Gets or sets the display friendly name.
/// </summary>
public string Name
{
get { return _name; }
set
{
_name = value;
FirePropertyChangedNotification("Name");
if (_displayText == null) { FirePropertyChangedNotification("DisplayText"); }
}
}
/// <summary>
/// Gets or sets the display text that is used in TreeView nodes. When null, uses the Name.
/// </summary>
public string DisplayText
{
get { return _displayText ?? Name; }
set { _displayText = value; FirePropertyChangedNotification("DisplayText"); }
}
/// <summary>
/// Gets a read/write list of values. Is never null.
/// </summary>
public BindingList<string> Values
{
get { return _values; }
set { _values = value ?? new BindingList<string>(); }
}
#region Events
public event PropertyChangedEventHandler PropertyChanged;
protected void FirePropertyChangedNotification(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
原来我只需要更改为BindingList<FilterDimension>
而不是List<FilterDimension
。。。我完全没有注意到控件期望通知从列表中弹出。