在ShellViewModel我有以下命令結合打開一個新窗口「遠程查看」WPF:團結:重用窗口已經關閉後
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()我得到無效操作excepton:不能設置可見或調用Show,ShowDialog的,或WindowInteropHelper。在窗口關閉後確保處理。
在Unity 中是否有任何解決方法可以在窗口實例關閉的情況下再次獲取窗口實例。
你的意思是? private ICommand _remoteViewCommand; public ICommand RemoteViewCommand { get {return _remoteViewCommand (_remoteViewCommand = new RelayCommand(RemoteViewExecute,CanRemoteViewExecute)); } } }這沒有幫助。我實際上是在尋找一種通過團結來實現的方式。 – Anees 2012-04-25 12:36:01
@Andy - 不確定你的意思是「通過Unity」(不是很熟悉Unity的大部分)。這個鏈接有幫助嗎? http://answers.unity3d.com/questions/20949/singleton-implementation.html – IAmTimCorey 2012-04-25 12:45:21
非常感謝你的幫助。 統一我的意思是:http://stackoverflow.com/questions/608585/can-someone-explain-microsoft-unity – Anees 2012-04-25 13:16:23