ContextMenu Placement and PlacementTarget intermittently not being respected
Posted: 29 Sep 2022, 23:54
Hello,
We are running into a weird intermittent issue with the placement of ContextMenus. Sometimes when we open our app, the ContextMenuService.PlacementTarget and ContextMenuService.Placement properties that we set in a element is not respected and the ContextMenu is instead always placed at the mouse cursor position. The issue is intermittent though, so sometimes it works as expected and sometimes it does not, it only happens when we open the app, if we open the app and it works once then it always works and vice versa.
I tried to reproduce this in one of the Noesis samples but I couldn't, it always worked as expected when I isolate everything. I'm suspecting this could be a bug with Noesis when interacting with some other elements, just like the case we saw the other day with the TreeView. So maybe you guys could ask some questions about things that I could test to help us narrow down the issue, and figure it out if this is a bug or just a mistake on our side.
The setup we have is something like this:
this is the ItemTemplate of a TreeViewItem.
We are running into a weird intermittent issue with the placement of ContextMenus. Sometimes when we open our app, the ContextMenuService.PlacementTarget and ContextMenuService.Placement properties that we set in a element is not respected and the ContextMenu is instead always placed at the mouse cursor position. The issue is intermittent though, so sometimes it works as expected and sometimes it does not, it only happens when we open the app, if we open the app and it works once then it always works and vice versa.
I tried to reproduce this in one of the Noesis samples but I couldn't, it always worked as expected when I isolate everything. I'm suspecting this could be a bug with Noesis when interacting with some other elements, just like the case we saw the other day with the TreeView. So maybe you guys could ask some questions about things that I could test to help us narrow down the issue, and figure it out if this is a bug or just a mistake on our side.
The setup we have is something like this:
Code: Select all
<DataTemplate x:Key="TreeViewComponentStyle">
<Border x:Name="OuterBorder" ContextMenuService.Placement="Left" ContextMenuService.PlacementTarget="{Binding ElementName=OuterBorder}">
<Border.ContextMenu>
<ContextMenu Name="MyContextMenu">
<MenuItem Header="Test" />
</ContextMenu>
</Border.ContextMenu>
<b:Interaction.Triggers>
<noesis:GamepadTrigger Button="Accept" FiredOn="ButtonDown">
<b:ChangePropertyAction TargetName="MyContextMenu" PropertyName="IsOpen" Value="True" />
<b:Interaction.Behaviors>
<b:ConditionBehavior>
<b:ConditionalExpression ForwardChaining="And">
<b:ComparisonCondition LeftOperand="{Binding Path=DataContext.SOMETHING, ElementName=MainWindow}" Operator="Equal" RightOperand="{x:Static model:VALUE_FROM_OUR_VIEW_MODEL}" />
<b:ComparisonCondition LeftOperand="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}, Path=IsSelected}" Operator="Equal" RightOperand="True" />
</b:ConditionalExpression>
</b:ConditionBehavior>
</b:Interaction.Behaviors>
</noesis:GamepadTrigger>
</b:Interaction.Triggers>
</Border>
</DataTemplate>