WPF DataGrid loses focus on ContextMenu -


There is a context menu specified in my datagram, which contains commands to do something with the selected rows. Works.

The problem is, every time the context menu opens (either through the right mouse button or menu key), the datagrid loses its focus and changes its background color to blue in the selected row Gray It is such a big contrast that the user gets the impression that selection has been cleared and it is not certain that the context menu opens to the right row.

This color change is absolutely fine, a non-centered item should not have focus color but should not trigger it by opening a context menu.

Here are some XML code:

  & lt; DataGrid HeadersVisibility = "Column" HorizontalGridLinesBrush = "# cccccc" VerticalGridLinesBrush = "#cccccc" BorderBrush = "# cccccc" Background = "{x: Null}" CanUserReorderColumns = "False" IsReadOnly = "True" ItemsSource = "{MyItems Binding, NotifyOnTargetUpdated = True} "AutoGenerateColumns =" ​​False "SelectionChanged =" DataGrid_SelectionChanged "& gt; & Lt; DataGrid.Columns & gt; & Lt; DataGridTextColumn ... /> & Lt; DataGridTextColumn ... /> & Lt; DataGridTextColumn ... /> & Lt; /DataGrid.Columns> & Lt; DataGrid.ContextMenu & gt; & Lt; ContextMenu DataContext = "{Binding Placement Target. Datacontext, Relative Source = {Relative Asris}}" & gt; & Lt; MenuItem header = "command text" command = "{binding micromand}" /> & Lt; / ContextMenu & gt; & Lt; /DataGrid.ContextMenu> & Lt; / Data grid & gt;  

and the annotated screenshot of this issue:

Screenshot

How can I fix this?

Since I just got the same problem, I got a solution on the solution (for me) in another question :

I just copied the DataGridCell style in my code and it worked.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -