Hi,
I've added a context menu to a couple of XamDataGrids in my application. If I right-click on the currently selected row, when the context menu appears the row still appears as highlighted - fine.
I want the users to also be able to right-click on a non-selected row, without actually selecting it. When I place the mouse over such a row, it is highlighted in a slightly different color than the selected row - again, fine. However, as soon as the context menu opens, the highlight goes away, which makes it less obvious to the user what the context menu refers to.
Is this normal behavior, or am I missing something here?
Thanks,Michel
Hello Michel,
Yes, this is the expected behavior. If you want you can change that of course. You can keep track of which record you are currently displaying the ContextMenu on, and change its DataRecordPresenter's background, or hightlight it in a way that will make it clear for the user.
Let me know if you have any questions on this.
Hi Alex,
Any hint as to exactly how to do that?
Michel,
Sorry for the late response. You can use for example something like this:
<Style TargetType="{x:Type igDP:DataRecordPresenter}">
<Style.Triggers>
<EventTrigger RoutedEvent="Control.ContextMenuOpening">
<BeginStoryboard>
<Storyboard>
<ColorAnimation To="AliceBlue" Storyboard.TargetProperty="Background.Color" Duration="0:0:0.1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Control.ContextMenuClosing">
<ColorAnimation To="Transparent" Storyboard.TargetProperty="Background.Color" Duration="0:0:3"/>
There is only one setback here. The ContextMenuClosing animation will not fire if you have opened one context menu and directly open another one on another record.
</Style.Triggers>
</Style>
To resolve this:
"There is only one setback here. The ContextMenuClosing animation will not fire if you have opened one context menu and directly open another one on another record."
I put this code in my ContextMenuOpening event handler:
drp = TryCast(Infragistics.Windows.Utilities.GetAncestorFromType(TryCast(e.OriginalSource, DependencyObject), GetType(DataRecordPresenter), True), DataRecordPresenter) If drp IsNot Nothing Then If _contextMenuSelectedDRP IsNot Nothing and _contextMenuSelectedDRP IsNot drp Then _contextMenuSelectedDRP.Background = Brushes.Transparent End If _contextMenuSelectedDRP = drp End If
_contextMenuSelectedDRP is a private class variable.