Exemple #1
0
        private async Task ExecuteCommandAsync(ScrollCommand cmd, CancellationToken token)
        {
            var suppress = false;

            switch (cmd.UpdateType)
            {
            case LineUp:
                Points.VerticalOffset -= Points.AverageItemHeight * Convert.ToInt32(cmd.Param);
                break;

            case LineDown:
                Points.VerticalOffset += Points.AverageItemHeight * Convert.ToInt32(cmd.Param);
                break;

            case LineLeft:
                Points.HorizontalOffset -= Points.AverageItemHeight * Convert.ToInt32(cmd.Param);        // for horizontal line increment, use vertical size
                break;

            case LineRight:
                Points.HorizontalOffset += Points.AverageItemHeight * Convert.ToInt32(cmd.Param);        // for horizontal line increment, use vertical size
                break;

            case PageUp:
                Points.VerticalOffset -= Points.ViewportHeight * Convert.ToInt32(cmd.Param);
                break;

            case PageDown:
                Points.VerticalOffset += Points.ViewportHeight * Convert.ToInt32(cmd.Param);
                break;

            case PageLeft:
                Points.HorizontalOffset -= Points.ViewportWidth * Convert.ToInt32(cmd.Param);
                break;

            case PageRight:
                Points.HorizontalOffset += Points.ViewportWidth * Convert.ToInt32(cmd.Param);
                break;

            case SetHorizontalOffset: {
                var(offset, thumbtrack) = ((double, ThumbTrack))cmd.Param;
                Points.HorizontalOffset = offset * (Points.HorizontalExtent - Points.ViewportWidth);
                suppress = thumbtrack == ThumbTrack.Track;
            }
            break;

            case SetVerticalOffset: {
                var(offset, thumbtrack) = ((double, ThumbTrack))cmd.Param;
                Points.VerticalOffset   = offset * (Points.VerticalExtent - Points.ViewportHeight);
                suppress = thumbtrack == ThumbTrack.Track;
            }
            break;

            case MouseWheel:
                Points.VerticalOffset -= Convert.ToInt32(cmd.Param);
                break;

            case SizeChange:
                Points.ViewportWidth  = ((Size)cmd.Param).Width;
                Points.ViewportHeight = ((Size)cmd.Param).Height;
                break;

            case Refresh:
            case Sort:
                break;

            case FocusUp:
                DataGrid.SelectedIndex = new GridIndex(Math.Max(DataGrid.SelectedIndex.Row - Convert.ToInt32(cmd.Param), 0), DataGrid.SelectedIndex.Column);
                await BringFocusedCellIntoViewAsync(token);

                return;

            case FocusDown:
                DataGrid.SelectedIndex = new GridIndex(Math.Min(DataGrid.SelectedIndex.Row + Convert.ToInt32(cmd.Param), DataProvider.RowCount - 1), DataGrid.SelectedIndex.Column);
                await BringFocusedCellIntoViewAsync(token);

                return;

            case FocusLeft:
                DataGrid.SelectedIndex = new GridIndex(DataGrid.SelectedIndex.Row, Math.Max(DataGrid.SelectedIndex.Column - Convert.ToInt32(cmd.Param), 0));
                await BringFocusedCellIntoViewAsync(token);

                return;

            case FocusRight:
                DataGrid.SelectedIndex = new GridIndex(DataGrid.SelectedIndex.Row, Math.Min(DataGrid.SelectedIndex.Column + Convert.ToInt32(cmd.Param), DataProvider.RowCount - 1));
                await BringFocusedCellIntoViewAsync(token);

                return;

            case FocusPageUp:
                DataGrid.SelectedIndex = new GridIndex(Math.Max(DataGrid.SelectedIndex.Row - Convert.ToInt32(cmd.Param), 0), DataGrid.SelectedIndex.Column);
                await BringFocusedCellIntoViewAsync(token);

                return;

            case FocusPageDown:
                DataGrid.SelectedIndex = new GridIndex(Math.Min(DataGrid.SelectedIndex.Row + Convert.ToInt32(cmd.Param), DataProvider.RowCount - 1), DataGrid.SelectedIndex.Column);
                await BringFocusedCellIntoViewAsync(token);

                return;

            case SetFocus:
                DataGrid.SelectedIndex = (GridIndex)cmd.Param;
                await BringFocusedCellIntoViewAsync(token);

                return;

            case HeaderFocusLeft:
                ColumnHeader.SelectedIndex = new GridIndex(ColumnHeader.SelectedIndex.Row, Math.Max(ColumnHeader.SelectedIndex.Column - Convert.ToInt32(cmd.Param), 0));
                await BringFocusedHeaderIntoViewAsync(token);

                return;

            case HeaderFocusRight:
                ColumnHeader.SelectedIndex = new GridIndex(ColumnHeader.SelectedIndex.Row, Math.Min(ColumnHeader.SelectedIndex.Column + Convert.ToInt32(cmd.Param), DataProvider.RowCount - 1));
                await BringFocusedHeaderIntoViewAsync(token);

                return;

            case SetHeaderFocus:
                ColumnHeader.SelectedIndex = (GridIndex)cmd.Param;
                await BringFocusedHeaderIntoViewAsync(token);

                return;

            case Invalid:
            default:
                return;
            }

            await DrawVisualsAsync(cmd.UpdateType, suppress, token, _owner.ColumnHeader?.SortOrder);
        }
Exemple #2
0
        private async Task ExecuteCommandAsync(ScrollCommand cmd, CancellationToken token) {
            bool drawVisual = true;
            bool suppress = false;
            switch (cmd.UpdateType) {
                case GridUpdateType.LineUp:
                    Points.VerticalOffset -= Points.AverageItemHeight * (double)cmd.Param;
                    break;
                case GridUpdateType.LineDown:
                    Points.VerticalOffset += Points.AverageItemHeight * (double)cmd.Param;
                    break;
                case GridUpdateType.LineLeft:
                    Points.HorizontalOffset -= Points.AverageItemHeight * (double)cmd.Param;    // for horizontal line increment, use vertical size
                    break;
                case GridUpdateType.LineRight:
                    Points.HorizontalOffset += Points.AverageItemHeight * (double)cmd.Param;    // for horizontal line increment, use vertical size
                    break;
                case GridUpdateType.PageUp:
                    Points.VerticalOffset -= Points.ViewportHeight * (double)cmd.Param;
                    break;
                case GridUpdateType.PageDown:
                    Points.VerticalOffset += Points.ViewportHeight * (double)cmd.Param;
                    break;
                case GridUpdateType.PageLeft:
                    Points.HorizontalOffset -= Points.ViewportWidth * (double)cmd.Param;
                    break;
                case GridUpdateType.PageRight:
                    Points.HorizontalOffset += Points.ViewportWidth * (double)cmd.Param;
                    break;
                case GridUpdateType.SetHorizontalOffset: {
                        var args = (Tuple<double, ThumbTrack>)cmd.Param;
                        Points.HorizontalOffset = args.Item1 * (Points.HorizontalExtent - Points.ViewportWidth);
                        suppress = args.Item2 == ThumbTrack.Track;
                    }
                    break;
                case GridUpdateType.SetVerticalOffset: {
                        var args = (Tuple<double, ThumbTrack>)cmd.Param;
                        Points.VerticalOffset = args.Item1 * (Points.VerticalExtent - Points.ViewportHeight);
                        suppress = args.Item2 == ThumbTrack.Track;
                    }
                    break;
                case GridUpdateType.MouseWheel:
                    Points.VerticalOffset -= (double)cmd.Param;
                    break;
                case GridUpdateType.SizeChange:
                    Points.ViewportWidth = ((Size)cmd.Param).Width;
                    Points.ViewportHeight = ((Size)cmd.Param).Height;
                    break;
                case GridUpdateType.Refresh:
                case GridUpdateType.Sort:
                    break;
                case GridUpdateType.Invalid:
                default:
                    drawVisual = false;
                    break;
            }

            if (drawVisual) {
                await DrawVisualsAsync(cmd.UpdateType, suppress, token, _owner.ColumnHeader?.SortOrder);
            }
        }
Exemple #3
0
        private async Task ExecuteCommandAsync(ScrollCommand cmd, CancellationToken token)
        {
            bool drawVisual = true;
            bool suppress   = false;

            switch (cmd.UpdateType)
            {
            case GridUpdateType.LineUp:
                Points.VerticalOffset -= Points.AverageItemHeight * (double)cmd.Param;
                break;

            case GridUpdateType.LineDown:
                Points.VerticalOffset += Points.AverageItemHeight * (double)cmd.Param;
                break;

            case GridUpdateType.LineLeft:
                Points.HorizontalOffset -= Points.AverageItemHeight * (double)cmd.Param;        // for horizontal line increment, use vertical size
                break;

            case GridUpdateType.LineRight:
                Points.HorizontalOffset += Points.AverageItemHeight * (double)cmd.Param;        // for horizontal line increment, use vertical size
                break;

            case GridUpdateType.PageUp:
                Points.VerticalOffset -= Points.ViewportHeight * (double)cmd.Param;
                break;

            case GridUpdateType.PageDown:
                Points.VerticalOffset += Points.ViewportHeight * (double)cmd.Param;
                break;

            case GridUpdateType.PageLeft:
                Points.HorizontalOffset -= Points.ViewportWidth * (double)cmd.Param;
                break;

            case GridUpdateType.PageRight:
                Points.HorizontalOffset += Points.ViewportWidth * (double)cmd.Param;
                break;

            case GridUpdateType.SetHorizontalOffset: {
                var args = (Tuple <double, ThumbTrack>)cmd.Param;
                Points.HorizontalOffset = args.Item1 * (Points.HorizontalExtent - Points.ViewportWidth);
                suppress = args.Item2 == ThumbTrack.Track;
            }
            break;

            case GridUpdateType.SetVerticalOffset: {
                var args = (Tuple <double, ThumbTrack>)cmd.Param;
                Points.VerticalOffset = args.Item1 * (Points.VerticalExtent - Points.ViewportHeight);
                suppress = args.Item2 == ThumbTrack.Track;
            }
            break;

            case GridUpdateType.MouseWheel:
                Points.VerticalOffset -= (double)cmd.Param;
                break;

            case GridUpdateType.SizeChange:
                Points.ViewportWidth  = ((Size)cmd.Param).Width;
                Points.ViewportHeight = ((Size)cmd.Param).Height;
                break;

            case GridUpdateType.Refresh:
            case GridUpdateType.Sort:
                break;

            case GridUpdateType.Invalid:
            default:
                drawVisual = false;
                break;
            }

            if (drawVisual)
            {
                await DrawVisualsAsync(cmd.UpdateType, suppress, token, _owner.ColumnHeader?.SortOrder);
            }
        }