Example #1
0
        public override List <ElementSite> CaptureOrderedSequence(UIElement source)
        {
            var grid = GetParentGrid(source);

            List <ElementSite> elementSites = grid.ColumnDefinitions.Any(c => ReferenceEquals(source, OrderableBehavior.GetDragHeader(c))) ? GetColumnSequence(grid) : GetRowSequence(grid);

            ((DefinitionSite)OrderableBehavior.GetSite(source)).IsAnimationEnabled = false;

            return(elementSites);
        }
Example #2
0
        public override void ReleaseOrderedSequence(UIElement source, List <ElementSite> elements)
        {
            var grid = GetParentGrid(source);

            Action <UIElement, int> setDef;
            Action <DefinitionSite> addDef;

            if (grid.ColumnDefinitions.Any(c => ReferenceEquals(source, OrderableBehavior.GetDragHeader(c))))
            {
                grid.ColumnDefinitions.Clear();
                setDef = Grid.SetColumn;
                addDef = d => grid.ColumnDefinitions.Add((ColumnDefinition)d.Definition);
            }
            else
            {
                grid.RowDefinitions.Clear();
                setDef = Grid.SetRow;
                addDef = d => grid.RowDefinitions.Add((RowDefinition)d.Definition);
            }

            for (var i = 0; i < elements.Count; i++)
            {
                var site = (DefinitionSite)elements[i];

                if (site.Children != null)
                {
                    foreach (var child in site.Children)
                    {
                        setDef(child, i);
                    }
                }

                addDef(site);
            }

            var elementSite = (DefinitionSite)OrderableBehavior.GetSite(source);

            elementSite.IsAnimationEnabled = true;
            elementSite.Offset             = OrderableBehavior.CalcElementOffset(elements, elementSite);

            grid.UpdateLayout();
            foreach (var site in elements.DirectCast <DefinitionSite>())
            {
                site.UpdateRenderOffset();
                site.QueryDispose();
            }
        }
Example #3
0
        public DefinitionSite(Grid grid, DefinitionBase definition)
            : base(GetOffset(definition), GetSize(definition), GetOrientation(definition))
        {
            this.definition = definition;

            OrderableBehavior.SetSite(definition, this);
            DragHeader = OrderableBehavior.GetDragHeader(definition);


            var isColumn = definition is ColumnDefinition;
            var defIndex = isColumn
                       ? grid.ColumnDefinitions.IndexOf((ColumnDefinition)definition)
                       : grid.RowDefinitions.IndexOf((RowDefinition)definition);

            var getDef = isColumn ? (Func <UIElement, int>)Grid.GetColumn : Grid.GetRow;

            Children = grid.Children.OfType <FrameworkElement>().Where(c => getDef(c) == defIndex).ToList();

            if (DragHeader == null)
            {
                return;
            }

            OrderableBehavior.SetSite(DragHeader, this);


            foreach (var child in Children)
            {
                AddSiteRenderTransform(child, SiteRenderTransform);

                if (child == DragHeader)
                {
                    continue;
                }

                BindingOperations.SetBinding(child, UIElement.OpacityProperty, new Binding("Opacity")
                {
                    Source = DragHeader
                });
                BindingOperations.SetBinding(child, Panel.ZIndexProperty, new Binding("(Panel.ZIndex)")
                {
                    Source = DragHeader
                });
            }

            RenderOffset = Offset;
        }
Example #4
0
        protected override ElementSite GetActualSite(DependencyObject dependencyObject)
        {
            foreach (var ancestor in dependencyObject.GetAncestorsAndSelf(VisualTreeEnumerationStrategy.Instance))
            {
                var site = GetElementSite(ancestor);

                if (site != null)
                {
                    return(site);
                }

                if (ReferenceEquals(this, OrderableBehavior.GetAdvisor(ancestor)))
                {
                    break;
                }
            }

            return(null);
        }
Example #5
0
        private ElementSite GetCurrentSite(DefinitionBase definition)
        {
            var site = OrderableBehavior.GetSite(definition) as DefinitionSite;

            if (site == null)
            {
                return(null);
            }

            site.CancelDisposing();

            if (ReferenceEquals(site.DragHeader, DraggableBehavior.DraggedElement))
            {
                site.Offset             = site.RenderOffset;
                site.IsAnimationEnabled = false;
            }

            return(site);
        }