Closed danipen closed 1 year ago
How are you assigning the context menu? I'm not seeing this behavior in the sample app:
https://user-images.githubusercontent.com/1775141/231992381-8a61e600-7c2e-40a4-bec2-741bcf88e9bd.mp4
We're using:
mTreeDataGrid.ContextRequested += TreeDataGridEventHandlers.ContextRequested;
And then:
void ContextRequested(object sender, ContextRequestedEventArgs e)
{
if (IsClickedOnHeader(e))
return;
e.TryGetPosition(targetControl, out Point p);
mMenu.Popup(targetControl, p);
}
Just tried this, and though I'm not sure exactly what you're doing (our ContextMenu
class doesn't have a Popup
method, not MenuFlyout
), I could reproduce with a MenuFlyout
. The fix was simple though: add e.Handled = true
to the ContextRequested
event handler. Does this fix the issue for you?
Yes, setting e.Handled = true
fixes the issue. Just note that in 0.10.x
this was not needed ...
Also, for ListBox
we're using the same approach and e.Handled = true
is not needed either.
The workaround is ok for us, since we manage the ContextRequested
event in a single place, so it's easy to workaround.
But you may want to review the behavior since it's different for the TreeDataGrid
and other lists, such as the ListBox
... Please let me know.
The problem comes from this line:
When the pointer is released, IsRightButtonPressed
is false
as the right button has been released. Will fix this.
note that in 0.10.x this was not needed
Strange, I tried the stable 0.10.x branch of TreeDataGrid
and I see the same behavior there; not sure what could have changed between 0.10.x and 11.x to cause a difference in behavior, but it's academic because the code has a bug.
Should be fixed by https://github.com/AvaloniaUI/Avalonia.Controls.TreeDataGrid/pull/168
As a one who added ContextRequested event, you are supposed to handle this event, if you have opened any context menu. Otherwise, the same event can be handled by parent control and second menu might be opened. Even if this specific issue can be avoided in TDG, it still should be handled.
We are displaying the context menu using
Control.ContextRequestedEvent
. Previously, is worked as expected, but since we migrated to preview 6, we're losing the selection when the context menu is being displayed: