示例#1
0
        private void SubscribePanelEvents(INotifyingPanel panel)
        {
            panel.ChildrenCreated -= notifyingItem_ChildrenCreated;

            panel.NotifyingChildren.CollectionChanged -= OnVisualCollectionChanged;
            panel.NotifyingChildren.CollectionChanged += OnVisualCollectionChanged;
        }
        private void notifyingItem_ChildrenCreated(object sender, EventArgs e)
        {
            //<function summary>

            //</function summary>
            INotifyingPanel panel = (INotifyingPanel)sender;

            SubscribePanelEvents(panel);
        }
        private void SubscribePanelEvents(INotifyingPanel panel)
        {
            //<function summary>
            //Set ChildrenCreated handler and update CollectionChanged Handler
            //</function summary>
            panel.ChildrenCreated -= notifyingItem_ChildrenCreated;

            panel.NotifyingChildren.CollectionChanged -= OnVisualCollectionChanged;
            panel.NotifyingChildren.CollectionChanged += OnVisualCollectionChanged;
        }
        private void OnVisualCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            //<function summary>
            // If there are new items in the collection then update the CollectionChanged handler
            // Call the OnVisualChildAdded handler with the UIElement related to each new item
            // Remove handlers from all the old items
            //</function summary>
            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    INotifyingPanel notifyingPanel = item as INotifyingPanel;
                    if (notifyingPanel != null)
                    {
                        if (notifyingPanel.NotifyingChildren != null)
                        {
                            notifyingPanel.NotifyingChildren.CollectionChanged -= OnVisualCollectionChanged;
                            notifyingPanel.NotifyingChildren.CollectionChanged += OnVisualCollectionChanged;
                        }
                        else
                        {
                            notifyingPanel.ChildrenCreated += notifyingItem_ChildrenCreated;
                        }
                    }

                    OnVisualChildAdded((UIElement)item, (UIElementCollection)sender);
                }
            }
            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    INotifyingPanel notifyingPanel = item as INotifyingPanel;
                    if (notifyingPanel != null)
                    {
                        notifyingPanel.ChildrenCreated -= notifyingItem_ChildrenCreated;
                        if (notifyingPanel.NotifyingChildren != null)
                        {
                            notifyingPanel.NotifyingChildren.CollectionChanged -= OnVisualCollectionChanged;
                        }
                    }

                    OnVisualChildRemoved((UIElement)item, (UIElementCollection)sender);
                }
            }
        }
示例#5
0
        private void OnVisualCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    INotifyingPanel notifyingPanel = item as INotifyingPanel;
                    if (notifyingPanel != null)
                    {
                        if (notifyingPanel.NotifyingChildren != null)
                        {
                            notifyingPanel.NotifyingChildren.CollectionChanged -= OnVisualCollectionChanged;
                            notifyingPanel.NotifyingChildren.CollectionChanged += OnVisualCollectionChanged;
                        }
                        else
                        {
                            notifyingPanel.ChildrenCreated += notifyingItem_ChildrenCreated;
                        }
                    }

                    OnVisualChildAdded((UIElement)item, (UIElementCollection)sender);
                }
            }
            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    INotifyingPanel notifyingPanel = item as INotifyingPanel;
                    if (notifyingPanel != null)
                    {
                        notifyingPanel.ChildrenCreated -= notifyingItem_ChildrenCreated;
                        if (notifyingPanel.NotifyingChildren != null)
                        {
                            notifyingPanel.NotifyingChildren.CollectionChanged -= OnVisualCollectionChanged;
                        }
                    }

                    OnVisualChildRemoved((UIElement)item, (UIElementCollection)sender);
                }
            }
        }
示例#6
0
        private void notifyingItem_ChildrenCreated(object sender, EventArgs e)
        {
            INotifyingPanel panel = (INotifyingPanel)sender;

            SubscribePanelEvents(panel);
        }
示例#7
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            addedVisualElements.Clear();

            foreach (var item in GetAllPanels())
            {
                INotifyingPanel panel = item as INotifyingPanel;
                if (panel != null)
                {
                    panel.ChildrenCreated -= notifyingItem_ChildrenCreated;
                    if (panel.NotifyingChildren != null)
                    {
                        panel.NotifyingChildren.CollectionChanged -= OnVisualCollectionChanged;
                    }
                }
            }

            var headerPanel = GetPart <StackPanel>("PART_HeaderPanel");

            MigrateChildren(this.headerPanel, headerPanel);
            this.headerPanel = headerPanel;

            var footerPanel = GetPart <StackPanel>("PART_FooterPanel");

            MigrateChildren(this.footerPanel, footerPanel);
            this.footerPanel = footerPanel;

            var leftPanel = GetPart <StackPanel>("PART_LeftPanel");

            MigrateChildren(this.leftPanel, leftPanel);
            this.leftPanel = leftPanel;

            var bottomPanel = GetPart <StackPanel>("PART_BottomPanel");

            MigrateChildren(this.bottomPanel, bottomPanel);
            this.bottomPanel = bottomPanel;

            var rightPanel = GetPart <StackPanel>("PART_RightPanel");

            MigrateChildren(this.rightPanel, rightPanel);
            this.rightPanel = rightPanel;

            var topPanel = GetPart <StackPanel>("PART_TopPanel");

            MigrateChildren(this.topPanel, topPanel);
            this.topPanel = topPanel;

            var mainCanvas = GetPart <Canvas>("PART_MainCanvas");

            MigrateChildren(this.mainCanvas, mainCanvas);
            this.mainCanvas = mainCanvas;

            var centralGrid = GetPart <Grid>("PART_CentralGrid");

            MigrateChildren(this.centralGrid, centralGrid);
            this.centralGrid = centralGrid;

            centralGridColumn = GetPart <ColumnDefinition>("PART_CentralGridColumn");
            leftAxisColumn    = GetPart <ColumnDefinition>("PART_LeftAxisColumn");
            rightAxisColumn   = GetPart <ColumnDefinition>("PART_RightAxisColumn");

            var mainGrid = GetPart <Grid>("PART_MainGrid");

            MigrateChildren(this.mainGrid, mainGrid);
            this.mainGrid = mainGrid;

            var parallelCanvas = GetPart <Canvas>("PART_ParallelCanvas");

            MigrateChildren(this.parallelCanvas, parallelCanvas);
            this.parallelCanvas = parallelCanvas;

            var contentsGrid = GetPart <Grid>("PART_ContentsGrid");

            MigrateChildren(this.contentsGrid, contentsGrid);
            this.contentsGrid = contentsGrid;

            Content = contentsGrid;
            AddLogicalChild(contentsGrid);

            foreach (var notifyingItem in GetAllPanels())
            {
                INotifyingPanel panel = notifyingItem as INotifyingPanel;
                if (panel != null)
                {
                    if (panel.NotifyingChildren == null)
                    {
                        panel.ChildrenCreated += notifyingItem_ChildrenCreated;
                    }
                    else
                    {
                        panel.NotifyingChildren.CollectionChanged += OnVisualCollectionChanged;
                    }
                }
            }
        }