コード例 #1
0
        public void OnLayoutLoaded(LayoutLoadedArgs args)
        {
            var matchingAnchorables = args.LayoutAnchorables.Where(anch => anch.Content.GetType() == Definition.View &&
                                                                   anch.Content.SafeCast <UserControl>().DataContext.GetType() == Definition.ViewModel &&
                                                                   anch.IsVisible);

            var rougeAnchorables = ActivePanels.Where(o => !matchingAnchorables.Select(anch => anch.Content.SafeCast <UserControl>().DataContext).
                                                      Contains(o.Content.SafeCast <UserControl>().DataContext));

            foreach (var anchorable in rougeAnchorables.ToList())
            {
                RemoveDynamicPanel(anchorable);
            }

            foreach (var invalidationSubscription in InvalidationSubscriptions)
            {
                invalidationSubscription.Event.Unsubscribe(invalidationSubscription.Token);
            }

            InvalidationSubscriptions.Clear();
            ActivePanels.Clear();
            foreach (var anchorable in matchingAnchorables)
            {
                ResolveDynamicPanelDependencies(anchorable);
                ActivePanels.Add(anchorable);
            }

            SyncSelection(ActivePanels.Select(o => o.Content.SafeCast <UserControl>().DataContext));
        }
コード例 #2
0
 private void ClearDynamicPanels()
 {
     foreach (var anchorable in ActivePanels.ToList())
     {
         RemoveDynamicPanel(anchorable);
     }
 }
コード例 #3
0
        private void RemoveDynamicPanel(LayoutAnchorable anchorable)
        {
            var invalidationSubscriptions = InvalidationSubscriptions.Where(o => o.Object == anchorable).ToList();

            foreach (var subscription in invalidationSubscriptions)
            {
                subscription.Break();
                InvalidationSubscriptions.Remove(subscription);
            }

            var view      = anchorable.Content.SafeCast <UserControl>();
            var viewModel = view.DataContext;

            view.DataContext = null;
            if (viewModel is IDestructible destructible)
            {
                destructible.TearDown();
            }

            anchorable.Hiding -= OnRemoveHandler;
            if (anchorable.GetRoot() == DockingView.DockingManager.Layout)
            {
                anchorable.Close();
            }

            ActivePanels.Remove(anchorable);
        }
コード例 #4
0
        public static void AddPanel(ScreenSafePanel panel)
        {
            if (ActivePanels.Contains(panel))
            {
                return;
            }

            ActivePanels.Add(panel);

            panel.ApplySafeArea(_currentSafeArea);
        }
コード例 #5
0
        private void AddDynamicPanel(LayoutAnchorable anchorable)
        {
            var container = GetPrefferedLayoutContainer();

            container.Children.Add(anchorable);
            container.SelectedContentIndex = container.Children.IndexOf(anchorable);

            ResolveDynamicPanelDependencies(anchorable);

            ActivePanels.Add(anchorable);
        }
コード例 #6
0
        public void BringPanelIntoView(object viewModel)
        {
            LayoutAnchorable anchorable = null;

            try
            {
                anchorable = ActivePanels.Single(o => o.Content.SafeCast <UserControl>().DataContext == viewModel);
            }
            catch (InvalidOperationException)
            {
                throw new Exception($"Error bringing the dynamic panel associated with the ViewModel instance of type {viewModel.GetType().Name} into view : \n " +
                                    $"The PanelSelectionBinding associated to the DynamicPanelDefinition of the given viewModelType does not contain the given instance");
            }

            var parent = anchorable.Parent.SafeCast <LayoutAnchorablePane>();

            parent.SelectedContentIndex = parent.Children.IndexOf(anchorable);
        }
コード例 #7
0
        private void OnSelectionBindingChanged()
        {
            var activeViewModels = ActivePanels.Select(o => o.Content.SafeCast <UserControl>().DataContext);

            var addedItems = ViewModelSelection.SelectedObject.Except(activeViewModels).ToList();

            foreach (var item in addedItems)
            {
                CreateAndAddDynamicPanel(item);
            }

            var removedItems = activeViewModels.Except(ViewModelSelection.SelectedObject).ToList();

            foreach (var item in removedItems)
            {
                var anchorable = ActivePanels.Single(anch => anch.Content.SafeCast <UserControl>().DataContext == item);
                RemoveDynamicPanel(anchorable);
            }
        }