Exemplo n.º 1
0
        private void ItemsOwner_TileDragEnded(object sender, TileViewDragEventArgs e)
        {
            Mouse.Capture(null);
            (e.DraggedItem as FrameworkElement).ReleaseMouseCapture();
            var columnWidth = this.DesiredSize.Width / this.ColumnsCount;
            var rowHeight   = this.DesiredSize.Height / this.RowsCount;

            var column = (int)(this.lastMousePosition.X / columnWidth);
            var row    = (int)(this.lastMousePosition.Y / rowHeight);
            var item   = e.DraggedItem as RadTileViewItem;

            if (!this.TrySwapTiles(item, this.secondTile))
            {
                var currentRow    = TileViewAttachedProperties.GetRow(item);
                var currentColumn = TileViewAttachedProperties.GetColumn(item);
                var rowSpan       = TileViewAttachedProperties.GetRowSpan(item);
                var columnSpan    = TileViewAttachedProperties.GetColumnSpan(item);
                this.MarkCells(currentRow, currentColumn, rowSpan, columnSpan, false);

                TileViewAttachedProperties.SetColumn(item, column);
                TileViewAttachedProperties.SetRow(item, row);

                this.FixOverlapping(row, column, rowSpan, columnSpan);
            }

            this.secondTile    = null;
            this.isTileDragged = false;
            this.InvalidateMeasure();
        }
Exemplo n.º 2
0
        private bool TrySwapTiles(RadTileViewItem tile1, RadTileViewItem tile2)
        {
            if (tile1 == null || tile2 == null)
            {
                return(false);
            }

            var fColumn     = TileViewAttachedProperties.GetColumn(tile1);
            var fRow        = TileViewAttachedProperties.GetRow(tile1);
            var fRowSpan    = TileViewAttachedProperties.GetRowSpan(tile1);
            var fColumnSpan = TileViewAttachedProperties.GetColumnSpan(tile1);

            var sColumn     = TileViewAttachedProperties.GetColumn(tile2);
            var sRow        = TileViewAttachedProperties.GetRow(tile2);
            var sRowSpan    = TileViewAttachedProperties.GetRowSpan(tile2);
            var sColumnSpan = TileViewAttachedProperties.GetColumnSpan(tile2);

            this.MarkCells(fRow, fColumn, fRowSpan, fColumnSpan, false);
            this.MarkCells(sRow, sColumn, sRowSpan, sColumnSpan, false);
            TileViewAttachedProperties.SetColumn(tile1, sColumn);
            TileViewAttachedProperties.SetRow(tile1, sRow);

            TileViewAttachedProperties.SetColumn(tile2, fColumn);
            TileViewAttachedProperties.SetRow(tile2, fRow);


            this.MarkCells(sRow, sColumn, fRowSpan, fColumnSpan, true);
            this.MarkCells(fRow, fColumn, sRowSpan, sColumnSpan, true);

            this.FixOverlapping(sRow, sColumn, fRowSpan, fColumnSpan);
            this.FixOverlapping(fRow, fColumn, sRowSpan, sColumnSpan);

            return(true);
        }
Exemplo n.º 3
0
        private void FixOverlapping(int row, int column, int rowSpan, int columnSpan)
        {
            var overlappingTiles = GetOverlappingTiles(row, column, rowSpan, columnSpan);

            foreach (var tile in overlappingTiles)
            {
                var desiredRow    = TileViewAttachedProperties.GetRow(tile);
                var desiredColumn = TileViewAttachedProperties.GetColumn(tile);

                var desiredRowSpan    = TileViewAttachedProperties.GetRowSpan(tile);
                var desiredColumnSpan = TileViewAttachedProperties.GetColumnSpan(tile);

                this.MarkCells(desiredRow, desiredColumn, desiredRowSpan, desiredColumnSpan, false);
            }

            this.MarkCells(row, column, rowSpan, columnSpan, true);

            foreach (var tile in overlappingTiles)
            {
                var desiredRow    = TileViewAttachedProperties.GetRow(tile);
                var desiredColumn = TileViewAttachedProperties.GetColumn(tile);

                var desiredRowSpan    = TileViewAttachedProperties.GetRowSpan(tile);
                var desiredColumnSpan = TileViewAttachedProperties.GetColumnSpan(tile);

                this.FindEmptyFirstCell(desiredRow, desiredColumn, desiredRowSpan, desiredColumnSpan, new bool[this.RowsCount, this.ColumnsCount]);
                var slot = this.freeSlot;
                if (slot.Key != -1)
                {
                    TileViewAttachedProperties.SetRow(tile, slot.Key);
                    TileViewAttachedProperties.SetColumn(tile, slot.Value);

                    this.MarkCells(slot.Key, slot.Value, desiredRowSpan, desiredColumnSpan, true);
                }
                this.freeSlot = new KeyValuePair <int, int>(-1, -1);
            }
        }