المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : WPF MVVM Dispose ViewModel



C# Programming
09-22-2011, 03:24 PM
Hi,

I have a treeview with one root node. This node has some children.

The root not is a "TreeViewItemViewModel". This class contains : "ObservableCollection Items" which are Children nodes.

At beginning, the root node is not expanded and "Children" is empty.

When I expand root node, I load data from DataBase in Children collection :

public override void LoadChildren() { this.Items.Clear(); List lstOp = DataBAse.GetAllOperations(); foreach (Operation op in lstOp) { this.Items.Add(new TreeViewItemViewModel(op)); } }
If I "unexpand" and expand the root node, I reload children...

public bool IsExpanded { get { return _isExpanded; } set { if (value != this._isExpanded) { this._isExpanded = value; RaisePropertyChanged("IsExpanded"); if (this._isExpanded) { this.LoadChildren(); } } } }

My issue : when I call "LoadChildren", Items list is cleared but viewmodel are always in memory...

Can someone help me ?