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;
}
}