Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent changing DragEffects in TreeDataGrid DragDrop event-handlers if AutoDragDropRows=false #284

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/Avalonia.Controls.TreeDataGrid/TreeDataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ internal void RaiseRowPrepared(TreeDataGridRow row, int rowIndex)

internal void RaiseRowDragStarted(PointerEventArgs trigger)
{
if (_source is null || RowSelection is null)
if (!AutoDragDropRows || _source is null || RowSelection is null)
return;

var allowedEffects = AutoDragDropRows && !_source.IsSorted ?
var allowedEffects = !_source.IsSorted ?
DragDropEffects.Move :
DragDropEffects.None;
var route = BuildEventRoute(RowDragStartedEvent);
Expand Down Expand Up @@ -596,8 +596,7 @@ private bool CalculateAutoDragDrop(
[NotNullWhen(true)] out DragInfo? data,
out TreeDataGridRowDropPosition position)
{
if (!AutoDragDropRows ||
e.Data.Get(DragInfo.DataFormat) is not DragInfo di ||
if (e.Data.Get(DragInfo.DataFormat) is not DragInfo di ||
_source is null ||
_source.IsSorted ||
di.Source != _source)
Expand Down Expand Up @@ -628,6 +627,9 @@ _source is null ||

private void OnDragOver(DragEventArgs e)
{
if (!AutoDragDropRows)
return;

if (!TryGetRow(e.Source as Control, out var row))
{
e.DragEffects = DragDropEffects.None;
Expand Down Expand Up @@ -664,11 +666,17 @@ private void OnDragOver(DragEventArgs e)

private void OnDragLeave(RoutedEventArgs e)
{
if (!AutoDragDropRows)
return;

StopDrag();
}

private void OnDrop(DragEventArgs e)
{
if (!AutoDragDropRows)
return;

StopDrag();

if (!TryGetRow(e.Source as Control, out var row))
Expand Down