A primitive control used for representing a preview of the manipulated CustomGridSplitter
Inheritance: Windows.UI.Xaml.Controls.ContentControl
Exemplo n.º 1
0
        private void StartPreviewDragging(Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            this.isDraggingPreview = true;
            this.previewPopup = new Popup
            {
                Width = this.parentGrid.ActualWidth,
                Height = this.parentGrid.ActualHeight
            };

            this.previewPopup.IsOpen = true;
            this.previewPopupHostGrid = new Grid
            {
                VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch,
                HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch
            };

            this.parentGrid.Children.Add(this.previewPopupHostGrid);
            if (this.parentGrid.RowDefinitions.Count > 0)
                Grid.SetRowSpan(this.previewPopupHostGrid, this.parentGrid.RowDefinitions.Count);
            if (this.parentGrid.ColumnDefinitions.Count > 0)
                Grid.SetColumnSpan(this.previewPopupHostGrid, this.parentGrid.ColumnDefinitions.Count);
            this.previewPopupHostGrid.Children.Add(this.previewPopup);

            this.previewGrid = new Grid
            {
                Width = this.parentGrid.ActualWidth,
                Height = this.parentGrid.ActualHeight
            };

            this.previewPopup.Child = this.previewGrid;

            foreach (var definition in this.parentGrid.RowDefinitions)
            {
                var definitionCopy = new RowDefinition
                {
                    Height = definition.Height,
                    MaxHeight = definition.MaxHeight,
                    MinHeight = definition.MinHeight
                };

                this.previewGrid.RowDefinitions.Add(definitionCopy);
            }

            foreach (var definition in this.parentGrid.ColumnDefinitions)
            {
                var w = definition.Width;
                var mxw = definition.MaxWidth;
                var mnw = definition.MinWidth;

                var definitionCopy = new ColumnDefinition();

                definitionCopy.Width = w;
                definition.MinWidth = mnw;
                if (!double.IsInfinity(definition.MaxWidth))
                {
                    definition.MaxWidth = mxw;
                }
                //{
                //    Width = definition.Width,
                //    MaxWidth = definition.MaxWidth,
                //    MinWidth = definition.MinWidth
                //};

                this.previewGrid.ColumnDefinitions.Add(definitionCopy);
            }

            this.previewGridSplitter = new CustomGridSplitter
            {
                Opacity = 0.0,
                ShowsPreview = false,
                Width = this.Width,
                Height = this.Height,
                Margin = this.Margin,
                VerticalAlignment = this.VerticalAlignment,
                HorizontalAlignment = this.HorizontalAlignment,
                ResizeBehavior = this.ResizeBehavior,
                ResizeDirection = this.ResizeDirection,
                KeyboardIncrement = this.KeyboardIncrement
            };

            Grid.SetColumn(this.previewGridSplitter, Grid.GetColumn(this));
            var cs = Grid.GetColumnSpan(this);
            if (cs > 0)
                Grid.SetColumnSpan(this.previewGridSplitter, cs);
            Grid.SetRow(this.previewGridSplitter, Grid.GetRow(this));
            var rs = Grid.GetRowSpan(this);
            if (rs > 0)
                Grid.SetRowSpan(this.previewGridSplitter, rs);
            this.previewGrid.Children.Add(this.previewGridSplitter);

            this.previewControlBorder = new Border
            {
                Width = this.Width,
                Height = this.Height,
                Margin = this.Margin,
                VerticalAlignment = this.VerticalAlignment,
                HorizontalAlignment = this.HorizontalAlignment,
            };

            Grid.SetColumn(this.previewControlBorder, Grid.GetColumn(this));
            if (cs > 0)
                Grid.SetColumnSpan(this.previewControlBorder, cs);
            Grid.SetRow(this.previewControlBorder, Grid.GetRow(this));
            if (rs > 0)
                Grid.SetRowSpan(this.previewControlBorder, rs);
            this.previewGrid.Children.Add(this.previewControlBorder);

            this.previewControl = new GridSplitterPreviewControl();
            if (this.PreviewStyle != null)
                this.previewControl.Style = this.PreviewStyle;
            this.previewControlBorder.Child = this.previewControl;

            this.previewPopup.Child = this.previewGrid;
            //await this.previewGridSplitter.WaitForLoadedAsync();

            //this.previewGridSplitter.OnPointerPressed(e);
            this.previewGridSplitter.dragPointer = e.Pointer.PointerId;
            this.previewGridSplitter.effectiveResizeDirection = this.DetermineEffectiveResizeDirection();
            this.previewGridSplitter.parentGrid = this.previewGrid;
            this.previewGridSplitter.lastPosition = e.GetCurrentPoint(this.previewGrid).Position;
            this.previewGridSplitter.isDragging = true;
            this.previewGridSplitter.StartDirectDragging(e);
            this.previewGridSplitter.DraggingCompleted += previewGridSplitter_DraggingCompleted;
        }
        private void StartPreviewDragging(Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            _isDraggingPreview = true;
            _previewPopup      = new Popup
            {
                Width  = _parentGrid.ActualWidth,
                Height = _parentGrid.ActualHeight
            };

            _previewPopup.IsOpen  = true;
            _previewPopupHostGrid = new Grid
            {
                VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Stretch,
                HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch
            };

            _parentGrid.Children.Add(_previewPopupHostGrid);
            if (_parentGrid.RowDefinitions.Count > 0)
            {
                Grid.SetRowSpan(_previewPopupHostGrid, _parentGrid.RowDefinitions.Count);
            }
            if (_parentGrid.ColumnDefinitions.Count > 0)
            {
                Grid.SetColumnSpan(_previewPopupHostGrid, _parentGrid.ColumnDefinitions.Count);
            }
            _previewPopupHostGrid.Children.Add(_previewPopup);

            _previewGrid = new Grid
            {
                Width  = _parentGrid.ActualWidth,
                Height = _parentGrid.ActualHeight
            };

            _previewPopup.Child = _previewGrid;

            foreach (var definition in _parentGrid.RowDefinitions)
            {
                var definitionCopy = new RowDefinition
                {
                    Height    = definition.Height,
                    MaxHeight = definition.MaxHeight,
                    MinHeight = definition.MinHeight
                };

                _previewGrid.RowDefinitions.Add(definitionCopy);
            }

            foreach (var definition in _parentGrid.ColumnDefinitions)
            {
                var w   = definition.Width;
                var mxw = definition.MaxWidth;
                var mnw = definition.MinWidth;

                var definitionCopy = new ColumnDefinition();

                definitionCopy.Width = w;
                definition.MinWidth  = mnw;
                if (!double.IsInfinity(definition.MaxWidth))
                {
                    definition.MaxWidth = mxw;
                }
                //{
                //    Width = definition.Width,
                //    MaxWidth = definition.MaxWidth,
                //    MinWidth = definition.MinWidth
                //};

                _previewGrid.ColumnDefinitions.Add(definitionCopy);
            }

            _previewGridSplitter = new CustomGridSplitter
            {
                Opacity             = 0.0,
                ShowsPreview        = false,
                Width               = this.Width,
                Height              = this.Height,
                Margin              = this.Margin,
                VerticalAlignment   = this.VerticalAlignment,
                HorizontalAlignment = this.HorizontalAlignment,
                ResizeBehavior      = this.ResizeBehavior,
                ResizeDirection     = this.ResizeDirection,
                KeyboardIncrement   = this.KeyboardIncrement
            };

            Grid.SetColumn(_previewGridSplitter, Grid.GetColumn(this));
            var cs = Grid.GetColumnSpan(this);

            if (cs > 0)
            {
                Grid.SetColumnSpan(_previewGridSplitter, cs);
            }
            Grid.SetRow(_previewGridSplitter, Grid.GetRow(this));
            var rs = Grid.GetRowSpan(this);

            if (rs > 0)
            {
                Grid.SetRowSpan(_previewGridSplitter, rs);
            }
            _previewGrid.Children.Add(_previewGridSplitter);

            _previewControlBorder = new Border
            {
                Width               = this.Width,
                Height              = this.Height,
                Margin              = this.Margin,
                VerticalAlignment   = this.VerticalAlignment,
                HorizontalAlignment = this.HorizontalAlignment,
            };

            Grid.SetColumn(_previewControlBorder, Grid.GetColumn(this));
            if (cs > 0)
            {
                Grid.SetColumnSpan(_previewControlBorder, cs);
            }
            Grid.SetRow(_previewControlBorder, Grid.GetRow(this));
            if (rs > 0)
            {
                Grid.SetRowSpan(_previewControlBorder, rs);
            }
            _previewGrid.Children.Add(_previewControlBorder);

            _previewControl = new GridSplitterPreviewControl();
            if (this.PreviewStyle != null)
            {
                _previewControl.Style = this.PreviewStyle;
            }
            _previewControlBorder.Child = _previewControl;

            _previewPopup.Child = _previewGrid;
            //await this.previewGridSplitter.WaitForLoadedAsync();

            //this.previewGridSplitter.OnPointerPressed(e);
            _previewGridSplitter._dragPointer = e.Pointer.PointerId;
            _previewGridSplitter._effectiveResizeDirection = this.DetermineEffectiveResizeDirection();
            _previewGridSplitter._parentGrid   = _previewGrid;
            _previewGridSplitter._lastPosition = e.GetCurrentPoint(_previewGrid).Position;
            _previewGridSplitter._isDragging   = true;
            _previewGridSplitter.StartDirectDragging(e);
            _previewGridSplitter.DraggingCompleted += PreviewGridSplitter_DraggingCompleted;
        }