コード例 #1
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);
        }
コード例 #2
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);
            }
        }