private IWindowView GetOrCreateWindowView( IWindowContent windowContent, IWindowSettings setting, IWindowView ownerWindow, bool isCreate, Type windowType = null) { this.CheckAndRemoveInvalidCache(); var needCreateView = this._windowCaches.ContainsKey(windowContent) == false || isCreate; if (needCreateView) { this.CreateWindowView(windowContent, setting, windowType); } var window = this._windowCaches[windowContent]; if (ownerWindow != null) { window.View.SetOwner(ownerWindow); } return(window.View); }
private IWindowView GetWindowView(IWindowContent windowContent) { if (windowContent == null) { return(null); } return(this._windowCaches.ContainsKey(windowContent) == false ? null : this._windowCaches[windowContent].View); }
public void ChangeContent(IWindowContent from, IWindowContent to) { if (this._windowCaches.ContainsKey(from) == false) { return; } var window = this._windowCaches[from]; window.Context.ContentContext = to; }
private IWindowView CreateWindowView(IWindowContent windowContent, IWindowSettings setting, Type targeType = null) { var modelType = windowContent.GetType(); var windowTypeName = modelType.Name.Replace("ViewModel", string.Empty); // 1. 특정 Window 타입이 없으면 CommonWindow 사용. // 2. 1번이 null 일 경우 캐쉬되어 있는 this._customWindowTypes 에서 windowContent 의 이름을 기준으로 찾아서 사용. // 3. 2번이 null 일 경우 전달 받은 타입 사용. var windowType = (targeType == null ? this._commonWindowType : this._customWindowTypes.FirstOrDefault(w => string.CompareOrdinal(w.Name, windowTypeName) == 0)) ?? targeType; if (windowType == null) { // TODO : need logging return(null); } var windowView = Activator.CreateInstance(windowType) as IWindowView; if (windowView == null) { // TODO : need logging return(null); } var dataContextInfo = windowType.GetProperty("DataContext"); // Window의 DataContext는 View에서 함께 생성한다. var dataContext = dataContextInfo?.GetValue(windowView); // Window의 ViewModel은 반드시 IWindowContext을 상속해야한다. var windowViewModel = dataContext as IWindowContext; if (windowViewModel == null) { // TODO : need logging return(null); } windowViewModel.Setting = setting; windowView.Initialize(setting); this._windowCaches.Add(windowContent, new WindowViewStore { View = windowView, Context = windowViewModel }); windowViewModel.ContentContext = windowContent; return(windowView); }
public void CloseWindow(IWindowContent windowViewModel) { var windowView = this.GetWindowView(windowViewModel); if (windowView == null) { // TODO : need logging. return; } windowView.Close(); this._windowCaches.Remove(windowViewModel); this.CheckAndRemoveInvalidCache(); }
public void SetOwner(IWindowContent targetViewModel, IWindowContent ownerViewModel) { var targetWindowView = this.GetWindowView(targetViewModel); if (targetWindowView == null) { // NOTE : 예외를 발생시켜야 하나? // TODO : need logging. return; } var ownerWindowView = this.GetWindowView(ownerViewModel); if (ownerWindowView == null) { // NOTE : 예외를 발생시켜야 하나? // TODO : need logging. return; } targetWindowView.SetOwner(ownerWindowView); }
public void ChangeWindowState(IWindowContent windowViewModel, WindowViewStates states) { var windowView = this.GetWindowView(windowViewModel); windowView?.ChangeWindowState(states); }
public IWindowView GetOrCreateWindow(IWindowContent windowContent, IWindowSettings setting, IWindowContent ownerViewModel = null, bool isCreate = false) { var ownerWindow = this.GetWindowView(ownerViewModel); return(this.GetOrCreateWindowView(windowContent, setting, ownerWindow, isCreate)); }
public void DragMove(IWindowContent windowViewModel) { var windowView = this.GetWindowView(windowViewModel); windowView?.MoveWindow(); }