Esempio n. 1
0
        /// <summary>
        /// Overridden method which is called while a new child is being added to the collection.
        /// Used to create thumb controls for each child, which is used to drag and resise the child.
        /// </summary>
        /// <param name="visualAdded">Item which got added</param>
        /// <param name="visualRemoved">Item which got removed</param>
        protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
        {
            VerticalDragThumb thumb = null;

            Expander expander = visualRemoved as Expander;

            if (expander != null)
            {
                expander.Collapsed -= new RoutedEventHandler(OnChildExpanderCollapsed);
            }

            expander = visualAdded as Expander;
            if (expander != null)
            {
                expander.Collapsed += new RoutedEventHandler(OnChildExpanderCollapsed);

                if (lastExpanderAdded != null)
                {
                    // Create a thumb control and associate with this child
                    thumb            = new VerticalDragThumb();
                    thumb.DragDelta += new DragDeltaEventHandler(OnThumbDragged);
                    this.Children.Insert(this.Children.Count - 1, thumb);
                    thumb.ExpanderAbove = lastExpanderAdded;
                    thumb.ExpanderBelow = expander;

                    base.OnVisualChildrenChanged(thumb, null);
                }

                lastExpanderAdded = expander;
            }

            base.OnVisualChildrenChanged(visualAdded, visualRemoved);
        }
Esempio n. 2
0
        /// <summary>
        /// Fired when user drags a thumb control to resise an expander
        /// </summary>
        private void OnThumbDragged(object sender, DragDeltaEventArgs e)
        {
            VerticalDragThumb thumb = sender as VerticalDragThumb;
            Expander          nextOpenExpanderAbove = GetNextExpander(thumb, true);
            Expander          nextOpenExpanderBelow = GetNextExpander(thumb, false);

            bool movingUp = e.VerticalChange < 0;

            // Check for moves which are not possible... or open or close expanders as needed to make the move...
            if (e.VerticalChange == 0)
            {
                return;
            }

            if (movingUp && ((thumb.ExpanderAbove.IsExpanded == false && nextOpenExpanderAbove == null) || GetNextExpander(thumb, false, false) == null))
            {
                return;
            }

            if (!movingUp && ((thumb.ExpanderBelow.IsExpanded == false && nextOpenExpanderBelow == null) || GetNextExpander(thumb, false, false) == null))
            {
                return;
            }

            if (movingUp && thumb.ExpanderBelow != null && thumb.ExpanderBelow.IsExpanded == false)
            {
                thumb.ExpanderBelow.IsExpanded = true;
                nextOpenExpanderBelow          = thumb.ExpanderBelow;
            }

            if (!movingUp && nextOpenExpanderAbove == null)
            {
                thumb.ExpanderAbove.IsExpanded = true;
                nextOpenExpanderAbove          = thumb.ExpanderAbove;
            }

            // Handle the expander above
            if (nextOpenExpanderAbove != null)
            {
                double currentHeight = (double)nextOpenExpanderAbove.GetValue(AllocatedSizeProperty);
                double newHeight     = currentHeight + e.VerticalChange;

                if (newHeight > nextOpenExpanderAbove.MinHeight)
                {
                    if (nextOpenExpanderAbove.IsExpanded == false)
                    {
                        nextOpenExpanderAbove.IsExpanded = true;
                    }
                    nextOpenExpanderAbove.SetValue(UserDefinedSizeProperty, newHeight);
                }
                else if (newHeight <= nextOpenExpanderAbove.MinHeight && nextOpenExpanderAbove.IsExpanded == true)
                {
                    nextOpenExpanderAbove.IsExpanded = false;
                    nextOpenExpanderAbove.SetValue(UserDefinedSizeProperty, null);
                }
            }

            // Handle the expander below
            if (nextOpenExpanderBelow != null)
            {
                double currentHeight = (double)nextOpenExpanderBelow.GetValue(AllocatedSizeProperty);
                double newHeight     = currentHeight - e.VerticalChange;

                if (newHeight > nextOpenExpanderBelow.MinHeight)
                {
                    if (nextOpenExpanderBelow.IsExpanded == false)
                    {
                        nextOpenExpanderBelow.IsExpanded = true;
                    }
                    nextOpenExpanderBelow.SetValue(UserDefinedSizeProperty, newHeight);
                }
                else if (newHeight <= nextOpenExpanderBelow.MinHeight && nextOpenExpanderBelow.IsExpanded == true)
                {
                    nextOpenExpanderBelow.IsExpanded = false;
                    nextOpenExpanderBelow.SetValue(UserDefinedSizeProperty, null);
                }

                if (thumb.ExpanderBelow != null && thumb.ExpanderBelow == lastExpanderAdded)
                {
                    nextOpenExpanderBelow.SetValue(UserDefinedSizeProperty, null);
                }
            }
        }