在 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() 时出现无效操作异常:无法设置可见性或在窗口关闭后调用 Show、ShowDialog 或 WindowInteropHelper.EnsureHandle。
如果关闭了,Unity 中是否有任何解决方法可以再次获取窗口实例。