Datagrid:Context menu not getting fired from RowStyle in MVVM pattern

Jun 18, 2009 at 8:54 AM
Edited Jun 18, 2009 at 11:42 AM

I am displaying context menu on click of datagrid row. Menus are getting displayed, but commands(Delegae command as we are using MVVM pattern) are not getting fired. Please see the below code and help in solving this issue. 


<ContextMenu x:Key="mycm1">


<MenuItem Command="{Binding Path=View}" Header="View"/>

<MenuItem Command="{Binding Path=Accept}" Header="Accept" IsEnabled="{Binding Path=IsAcceptEnabled}" />

</ContextMenu.Items ></ContextMenu>

<Style x:Key="defaultRowStyle" TargetType="{x:Type Controls:DataGridRow}">

<Setter Property="ContextMenu" Value="{StaticResource mycm1}">  




 <Controls:DataGrid x:Name="dataGrid" ItemsSource="{Binding Path =ReportData}" Background="{x:Null }" Style="{StaticResource GridStyle }" AlternatingRowBackground="{x:Null }" RowHeaderStyle="{StaticResource GridRowHeaderStyle }" ColumnHeaderStyle="{StaticResource GridColumnHeaderStyle }"  CellStyle="{StaticResource GridRowStyle}" RowStyle="{StaticResource defaultRowStyle}" CanUserAddRows="False" CanUserDeleteRows="False" AutoGenerateColumns="False" Margin="10,10,10,10" VerticalScrollBarVisibility="Auto" Grid.Row ="0" GridLinesVisibility="All" SelectionUnit="FullRow" HeadersVisibility ="Column" sSynchronizedWithCurrentItem="True" SelectionMode="Single" CanUserReorderColumns="True" CanUserResizeRows="False" CanUserResizeColumns="True" ClipboardCopyMode="ExcludeHeader" IsReadOnly="True" Events:GridAttachedBehavior.SelectionChanged="{Binding GridClick }"> 

<Controls:DataGrid.Columns><Controls:DataGridTextColumn Header=" Retail Quote Id " Binding="{Binding Path=QuoteId}" SortMemberPath ="QuoteId" ElementStyle="{StaticResource DataGridTextColumnTextStyle}" IsReadOnly ="True" Width="50" />

 <Controls:DataGridTextColumn Header=" Status " Binding="{Binding Path=QuoteStatusDescription}" SortMemberPath="QuoteStatusDescription" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnTextStyle}" Width="50" />


As mentioned above on click of View in context menu, Delegate command is not getting fired in GridViewModel.cs (Which is view model for the above xaml). Please help.

Note: context menu command is getting fired when the context menu is placed in <Datagrid.Contextmenu>. But the problem with this is that, context menu is getting displayed in empty spave below the grid and on click of headers also. In order to avoid this, I am displaying context menu on Row style. But with Rowstyle command is not getting fired.

Hope my problem is cleared from the above lines. please help on this asap.