Note that there are some explanatory texts on larger screens.

plurals
  1. POContextMenu on WPF DataGrid Row - Event does not trigger
    primarykey
    data
    text
    <p>I've searched a lot about this topic.. I have to say I'm quite new to WPF..</p> <p>here is my question: I have a datagrid and need a contextmenu at the datagrid-Row.</p> <p>I have this code:</p> <pre><code>&lt;Grid&gt; &lt;TabControl&gt; &lt;TabItem&gt; &lt;Grid&gt; &lt;DataGrid Grid.Row="2" Grid.ColumnSpan="3" AutoGenerateColumns="False" HorizontalAlignment="Stretch" Margin="6,6,0,0" Name="gridErrors" VerticalAlignment="Stretch" AlternatingRowBackground="Gainsboro" AlternationCount="2" SelectionChanged="gridErrors_SelectionChanged" IsEnabled="False"&gt; &lt;DataGrid.Resources&gt; &lt;ContextMenu x:Key="DataRowContextMenu"&gt; &lt;MenuItem Header="Detaillierte Fehlerbehandlung" /&gt; &lt;/ContextMenu&gt; &lt;/DataGrid.Resources&gt; &lt;DataGrid.RowStyle&gt; &lt;Style TargetType="{x:Type DataGridRow}" x:Name="styleForDataRow"&gt; &lt;EventSetter Event="PreviewMouseLeftButtonDown" Handler="OnDataGridRow_PreviewMouseLeftButtonDown" /&gt; &lt;Setter Property="ContextMenu" Value="{StaticResource DataRowContextMenu}"&gt; &lt;!--&lt;Setter.Value&gt; &lt;ContextMenu&gt; &lt;MenuItem Header="Detaillierte Fehlerbehandlung" /&gt; &lt;/ContextMenu&gt; &lt;/Setter.Value&gt;--&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/DataGrid.RowStyle&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Binding="{Binding Number}" Header="Input Nummer" IsReadOnly="True"&gt;&lt;/DataGridTextColumn&gt; &lt;DataGridTextColumn Binding="{Binding Error}" Header="Meldung" IsReadOnly="True"&gt;&lt;/DataGridTextColumn&gt; &lt;DataGridTextColumn Binding="{Binding DetailInfo}" Header="Detail" IsReadOnly="True"&gt;&lt;/DataGridTextColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/TabItem&gt; &lt;/TabControl&gt; &lt;/Grid&gt; </code></pre> <p>This works fine, I can see the Context Menu by right clickin on a row, but the only thing is that the Event is not fired (only when I left-clik in the Grid itself, not with the Context Menu)</p> <p>I would appreciate it if anybody can help me.. it would save my day :-))</p> <p>Thanks a lot in advance!</p> <p>kr!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload