/// <summary> /// Get child window of given type. If such window is /// not exist create new one /// /// Call from /// /// OpenChildWindow /// </summary> public Window GetViewChildInstance <TChildWindow>() where TChildWindow : Window { //if window is alredy exist just get it var res = _dictKViewModelVView. FirstOrDefault(a => a.Value != null && a.Value.GetType() == typeof(TChildWindow)); //if exist no need to create it if (res.Key != null) { return(_dictKViewModelVView[res.Key]); } //if not need to create it //first find type of view model for this type of win Type typeViewModel = _dictKTypeWindowVTypeViewModelChild. FirstOrDefault(a => a.Key == typeof(TChildWindow)).Value; //than find view model instance BaseViewModelChildWin viewMod = _dictKViewModelVView.FirstOrDefault(a => a.Key.GetType() == typeViewModel).Key; //than create win and return it _dictKViewModelVView[viewMod] = (TChildWindow)Activator.CreateInstance(typeof(TChildWindow)); viewMod.RegisterWindow(_dictKViewModelVView[viewMod]); return(_dictKViewModelVView[viewMod]); }
public void OpenViewChildOnStart(string typeOfWin) { //find type of view model for this type of win Type typeViewModel = _dictKTypeWindowVTypeViewModelChild. FirstOrDefault(a => a.Key.ToString() == typeOfWin).Value; if (typeViewModel == null) { return; } //than find view model instance BaseViewModelChildWin viewMod = _dictKViewModelVView.FirstOrDefault(a => a.Key.GetType() == typeViewModel).Key; Type type = Type.GetType(typeOfWin + ", Terminal"); //than create win _dictKViewModelVView[viewMod] = (Window)Activator.CreateInstance(type); // viewMod.RegisterWindow(_dictKViewModelVView[viewMod]); Window win = _dictKViewModelVView[viewMod]; CUtilWin.ShowActivated(ref win); win.Closed += new EventHandler(OnChildWindowClosed); // return win; }