【发布时间】:2012-05-06 02:48:24
【问题描述】:
在 ShellViewModel 我有下面的命令绑定来打开一个新窗口“远程视图”
public ICommand RemoteViewCommand
{
get { return new RelayCommand(RemoteViewExecute, CanRemoteViewExecute); }
}
private void RemoteViewExecute()
{
if (!CanRemoteViewExecute())
{
return;
}
var shellRemoteView = Application._Container.Resolve<ShellRemoteView>();
if (_ShellRemoteView.DataContext==null)
_ShellRemoteView.DataContext = Application._Container.Resolve<ShellRemoteViewModel>();
shellRemoteView.Show();
}
在启动时,我已经使用生命周期管理器注册了“ShellRemoteView”和“ShellRemoteViewModel”以获得单例实例。
_Container.RegisterType<ShellRemoteView>(new ContainerControlledLifetimeManager());
_Container.RegisterType<ShellRemoteViewModel>(new ContainerControlledLifetimeManager());
当 shellRemoteView.Show() 执行并关闭表单,然后再次调用 shellRemoteView.Show() 我得到 Invalid Operation exceptionon:Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after一个窗口已关闭。
Unity 中是否有任何变通方法如果窗口实例关闭,则再次获取窗口实例。
【问题讨论】:
标签: wpf mvvm unity-container