コード例 #1
0
        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);
        }
コード例 #2
0
        public void HidePane(PaneWrapper _wrapper)
        {
            if (_wrapper == null)
            {
                throw new ArgumentNullException();
            }

            if (_wrapper.Pane.Visible)
            {
                _wrapper.Pane.Visible = false;
            }
        }
コード例 #3
0
        public void ShowPane(PaneWrapper _wrapper)
        {
            if (_wrapper == null)
            {
                throw new ArgumentNullException();
            }

            if (!_wrapper.Pane.Visible)
            {
                _wrapper.Pane.Visible = true;
            }
        }
コード例 #4
0
        public void RemovePane(PaneWrapper _wrapper)
        {
            if (_wrapper == null)
            {
                throw new ArgumentNullException();
            }

            panes.Remove(_wrapper);

            if (Marshal.IsComObject(_wrapper.Window))
            {
                Marshal.ReleaseComObject(_wrapper.Window);
            }
        }