Completed
Last Updated: 07 Jul 2022 07:18 by ADMIN
Release LIB 2022.2.711 (11 July 2022)
Martin Ivanov
Created on: 30 Jun 2022 12:53
Category: GridView
Type: Bug Report
0
GridView: Column drag visual gets clipped

The GridView allows you to drag-to-reorder its columns. When start dragging the clicked element is accessed and a screenshot is made from it. Then the drag visual shows an image of the dragged column header. In some cases the drag visual gets clipped.

To work this around, you can subscribe the GridViewHeaderCell elements to the DragDropManager's DragInitialize event and replace the default drag visual with a custom one.

private void RadGridView_CellLoaded(object sender, Telerik.Windows.Controls.GridView.CellEventArgs e)
{
	if (e.Cell is GridViewHeaderCell)
	{
		Dispatcher.BeginInvoke(new Action(() =>
		{
			DragDropManager.AddDragInitializeHandler(e.Cell, OnHeaderCellDragInitialize, true);
		}));
	}
}

private void RadGridView_CellUnloaded(object sender, Telerik.Windows.Controls.GridView.CellEventArgs e)
{
	if (e.Cell is GridViewHeaderCell)
	{
		Dispatcher.BeginInvoke(new Action(() =>
		{
			DragDropManager.RemoveDragInitializeHandler(e.Cell, OnHeaderCellDragInitialize);
		}));
	}
}

private void OnHeaderCellDragInitialize(object sender, DragInitializeEventArgs e)
{
	var dragSource = e.OriginalSource as GridViewHeaderCell;
	if (dragSource != null)
	{
		var dragVisual = new Border()
		{
			BorderBrush = Brushes.LightGray,
			BorderThickness = new Thickness(1),
			Background = new SolidColorBrush(Colors.Bisque) { Opacity = 0.4 },
			Width = dragSource.ActualWidth,
			Height = dragSource.ActualHeight,
			Child = new TextBlock() 
			{ 
				Text = (string)dragSource.Column.Header,
				Margin = new Thickness(5, 0, 5, 0), 
				VerticalAlignment = VerticalAlignment.Center }
		};
		e.DragVisual = dragVisual;
	}
}

0 comments