We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

HeaderContextMenu in SfDataGrid derived class

Thread ID:

Created:

Updated:

Platform:

Replies:

127352 Nov 9,2016 11:18 AM Nov 11,2016 03:53 AM WPF 3
loading
Tags: SfDataGrid
Bernd
Asked On November 9, 2016 11:18 AM

Hello,

I have problems with a HeaderContextMenu in SfDataGrid. All worked fine until I derived SfDataGrid to an own class (MyDataGrid).

So in XAML instead of <syncfusion:SfDataGrid...> I use <local:MyDataGrid ...>

Other functionality works as expected but the HeaderContextMenu commands which are implemented with static commands do not work. The CanExecute() is called with obj = null instead of a GridContextMenuInfo type.

Excerpts from my code:

<ContextMenu x:Key="MyGridHeaderContextMenu">
<MenuItem Header="Sort ascending" Command="{Binding Source={x:Static Member=vw:GridContextMenuCommands.SortAscending}}" CommandParameter="{Binding}" />
...
</ContextMenu>


public static class GridContextMenuCommands
{
...
private static bool SortAscendingCanExecute(object obj)
{
if (obj is GridColumnContextMenuInfo)
{
var grid = (obj as GridContextMenuInfo).DataGrid;
...

Any hints?

Regards
Bernd


Jai Ganesh S [Syncfusion]
Replied On November 10, 2016 12:59 AM

Hi Bernd, 
We have prepared a sample for derived the SfDataGrid to custom class and create the HeaderContextMenu but its works fine in our end. 
<local:CustomSfDataGrid ItemsSource="{Binding GDCSource}" x:Name="datagrid"> 
 
            <local:CustomSfDataGrid.Columns> 
                <syncfusion:GridTextColumn MappingName="EmployeeName"/> 
                <syncfusion:GridTextColumn MappingName="EmployeeArea"/> 
                <syncfusion:GridTextColumn MappingName="EmployeeCity"/> 
                <syncfusion:GridTextColumn MappingName="EmployeeSalary"/> 
            </local:CustomSfDataGrid.Columns> 
 
            <local:CustomSfDataGrid.HeaderContextMenu> 
                <ContextMenu Style="{x:Null}"> 
                    <MenuItem Command="{Binding Source={x:Static Member=local:ContextMenucommand.SortAscending}}" 
                                      CommandParameter="{Binding}" 
                                      Header="Sort Ascending"/> 
                </ContextMenu> 
            </local:CustomSfDataGrid.HeaderContextMenu> 
</local:CustomSfDataGrid> 
 
Screen shot: 
 
 
Could you please check the above sample and let us know the details whether you have did any operations inside the customized SfDataGrid or if possible please replicate the issue in above sample. This would be more helpful for us to proceed further. 
Regards, 
Jai Ganesh S 


Bernd
Replied On November 10, 2016 04:16 AM

Jai,

thank you for your support. If ound the problem I had: I was assigning the ContextMenu from within the style which seems not to work on the derived control. The same applies to the GroupDropAreaStyle which cannot be assign from within a common style.

So this is NOT working:

<Style TargetType="{x:Type syncfusion:SfDataGrid}" x:Key="BaseGridStyle">
  <Setter Property="HeaderContextMenu" Value="{DynamicResource BaseGridHeaderContextMenu}"/>
  <Setter Property="GroupDropAreaStyle" Value="{DynamicResource BaseGridGroupDropAreaStyle}"/>

  <Setter Property="Background" Value="White"/>
</Style>

Any ideas how to change that?

And I encoutered a second problem: The ContextMenu no longer shows if the Grid is embedded in a TabControl and you switch the Tab and then go back to the Grid. I modified your sample to demonstrate the behaviour:

 <TabControl>
            <TabItem Header="Grid">
                <local:CustomSfDataGrid ItemsSource="{Binding GDCSource}" x:Name="datagrid">

                    <local:CustomSfDataGrid.Columns>
                        <syncfusion:GridTextColumn MappingName="EmployeeName"/>
                        <syncfusion:GridTextColumn MappingName="EmployeeArea"/>
                        <syncfusion:GridTextColumn MappingName="EmployeeCity"/>
                        <syncfusion:GridTextColumn MappingName="EmployeeSalary"/>
                    </local:CustomSfDataGrid.Columns>

                    <local:CustomSfDataGrid.HeaderContextMenu>
                        <ContextMenu Style="{x:Null}">
                            <MenuItem Command="{Binding Source={x:Static Member=local:ContextMenucommand.SortAscending}}"
                                          CommandParameter="{Binding}"
                                          Header="Sort Ascending"/>
                        </ContextMenu>
                    </local:CustomSfDataGrid.HeaderContextMenu>
                </local:CustomSfDataGrid>
            </TabItem>
            <TabItem Header="Second"/>
        </TabControl>

Why is that?

Best regards
Bernd

Jai Ganesh S [Syncfusion]
Replied On November 11, 2016 03:53 AM

Hi Bernd, 
A support incident to track the status of this query has been created under your account. Please log on to our support website to check for further updates 
Regards, 
Jai Ganesh S  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;