public PaneWrapper InitPane <T>(object _window, bool _createNew, out bool _isNew, Action <ViewModelBase> _callback = null, int _id = 0) where T : UserControl, new() { if (_window == null) { throw new ArgumentNullException(); } bool isPaneIsNew = false; PaneWrapper wrapper = GetPane(_window); if (!_createNew && wrapper != null && (wrapper.Pane.Control as CustomTaskPaneForm).ElementHost.Child.GetType() == typeof(T) && wrapper.Id == _id) { _isNew = false; return(wrapper); } else { wrapper = CreatePane(_window, _id); isPaneIsNew = true; } var paneWrapperCached = _createNew ? null : GetPane <T>(_id); if (paneWrapperCached != null) { wrapper.ViewModel = paneWrapperCached.ViewModel; _isNew = false; } else { _isNew = true; wrapper.ViewModel = CreateViewModel <T>(); _callback?.Invoke(wrapper.ViewModel); } UserControl uc = new T() { DataContext = wrapper.ViewModel }; (wrapper.Pane.Control as CustomTaskPaneForm).ElementHost.Child = uc; if (isPaneIsNew) { panes.Add(wrapper); } return(wrapper); }
public void HidePane(PaneWrapper _wrapper) { if (_wrapper == null) { throw new ArgumentNullException(); } if (_wrapper.Pane.Visible) { _wrapper.Pane.Visible = false; } }
public void ShowPane(PaneWrapper _wrapper) { if (_wrapper == null) { throw new ArgumentNullException(); } if (!_wrapper.Pane.Visible) { _wrapper.Pane.Visible = true; } }
public void RemovePane(PaneWrapper _wrapper) { if (_wrapper == null) { throw new ArgumentNullException(); } panes.Remove(_wrapper); if (Marshal.IsComObject(_wrapper.Window)) { Marshal.ReleaseComObject(_wrapper.Window); } }