【发布时间】:2011-07-26 17:41:24
【问题描述】:
如何确保我的子窗口在关闭时被卸载?
我正在从我的视图模型中打开子窗口,但在它关闭后,它仍然会触发组合框上的 selectionchanged 等事件。
子窗口使用与调用它的视图模型相同的视图模型,所以我想这解释了为什么会触发事件。 itemssource 仍然有效。
但是当它关闭时,我想永远“处置”子窗口。
我尝试添加这样的 Closed 处理程序(默认视图代码在后面):
private void OnLaunchEditItem(ItemMessage msg)
{
var editWnd = new EditItemWindow();
editWnd.Closed += new EventHandler(editWnd_Closed);
editWnd.Show();
}
void editWnd_Closed(object sender, EventArgs e)
{
sender = null;
}
没有成功..
所以我现在要做的是从子窗口控件中删除 itemssource,在我看来这不是解决问题的理想方法。必须有可能在关闭时从内存中全部处理掉? (子窗口“查看”代码隐藏)
private void OKButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
combobox1.ItemsSource = null;
combobox2.ItemsSource = null;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
combobox1.ItemsSource = null;
combobox2.ItemsSource = null;
}
【问题讨论】:
标签: silverlight mvvm-light childwindow