我有一個問題,我的silverlight treeview綁定到可觀察集合。除了當我嘗試編輯樹視圖中的現有項目時,樹視圖綁定在所有操作中都可以正常工作,其中我彈出一個新的子窗口並將樹管理器對象傳遞給它。 Treemanager本質上是一個維護我可觀察集合的自定義類。代碼更新可觀察集合中的基礎項目,就好像它看起來有一個指向樹管理器對象的指針,但它並不更新樹視圖,即使我明確地告訴它重新綁定到可存儲集合。Observable集合不更新treeview使用silverlight子窗口
代碼右鍵點擊:
TreeViewItem treeItem = this.RCM.GetClickedElement<TreeViewItem>();// as TreeViewItem;
TreeManager treeManager = ((TreeManager)(((HeaderedItemsControl)(treeItem)).Header));
if (treeManager.Type != "diObject")
{
Message.ErrorMessage("Please select the root DiObject to edit");
return;
}
EditWindow editdlg = new EditWindow(DiObjectNameToList(treeManager), driverComboItems, deviceIntTypeComboItems);
editdlg.Title = "Edit DIObject - "+treeManager.Title;
editdlg.Closed += new EventHandler(editdlg_Closed);
editdlg.t_orig = treeManager;
editdlg.t = treeManager;
editdlg.Show();
子視圖窗口:
public partial class EditWindow : ChildWindow
{
Dictionary<string, string> diObject;
String[] driverComboItems;
String[] deviceIntTypeComboItems;
public TreeManager t { get; set; }
public TreeManager t_orig { get; set; }
public EditWindow(Dictionary<string, string> _diObject, String[] _driverComboItems, String[] _deviceIntTypeComboItems)
{..}
}
treeManager類:
public class TreeManager
{
public TreeManager() { }
public TreeManager(string title)
{
Title = title;
}
public string Title { get; set; }
public ObservableCollection<TreeManager> childElementsValue = new ObservableCollection<TreeManager>();
public ObservableCollection<TreeManager> ChildElements
{
get { return childElementsValue; }
set { childElementsValue = value; }
}
}
你不需要實現INotifyPropertyChanged。問題是他直接設置列表,並且Observablecollection不會通知它是否直接設置,只有當您執行.Add();清除()等... – MBen 2011-12-15 14:10:09