This is a migrated thread and some comments may be shown as answers.

Creating a Base Class for RadGridView using a ContextMenu

2 Answers 70 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Abhinav
Top achievements
Rank 1
Abhinav asked on 07 Nov 2016, 09:26 PM

Hi,

We've created a base class/control which implements RadGridView (i.e. BaseGridView : RadGridView) which features code-behind logic that is bound to the UI's RadGridView, which we'd like to use across our application to elimintate repeated code.

We were able to create a solution that worked, however, we were required to create the RadContextMenu and the items manually in the base controls' constructor, where we would prefer to declare the RadContextMenu and the items in the XAML of the base control, like so:

<telerik:RadGridView x:Class="MyModule.BaseGridView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
...
<telerik:RadContextMenu x:Name="GridContextMenu">
            <telerik:RadContextMenu.Items>
                <telerik:RadMenuItem Name="mnuFilterItem" Header="Filter Selected" Click="FilterMenuItem_OnClick"/>
            </telerik:RadContextMenu.Items>
        </telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>
...
</telerik:RadGridView>

Here is sample usage in a View which implements the base control:

...

<views:BaseGridView Grid.Row="1" 
                            ItemsSource="{Binding Path=MyData}" 
                             AutoGenerateColumns="False" 
                             IsReadOnly="False" 
                             RowIndicatorVisibility="Visible"
                             HorizontalAlignment="Stretch"
                             SelectionMode="Extended"
                             SelectionUnit="Mixed"
                             ClipboardPasteMode="AllSelectedCells">

...

The XAML implementation is triggering the FilterMenuItem_OnClick event from the View which inherits this base view/control, however, we are experiencing a XAML exception when viewing the XAML in the designer of the View which is implementing the base control:

Method not found: 'Void Telerik.Windows.Controls.RadMenuItem.add_Click(Telerik.Windows.RadRoutedEventHandler)'.

 

Kindly advise. We have also tried manually hooking up the filter's click event in code-behind in the inheriting View's constructor like so:

mnuFilterItem.Click += new RadRoutedEventHandler(FilterMenuItem_OnClick);

However, the XAML exception in the implementing View persists.

 

Kind regards

2 Answers, 1 is accepted

Sort by
0
Abhinav
Top achievements
Rank 1
answered on 07 Nov 2016, 09:52 PM

Hi,

We also get this exception when adding the menuitems of the ContextMenu manually in the base View's contructor - the exception didn't appear until the View implementing the base view was reopened; exception:

Method not found: 'Void Telerik.Windows.Controls.RadMenuItem.add_Click(Telerik.Windows.RadRoutedEventHandler)'.

Kindly advise.

Kind regards.

 

0
Stefan Nenchev
Telerik team
answered on 09 Nov 2016, 01:38 PM
Hello Abhinav,

I have tried replicating the issue you have reported but to no avail. I do not see such XAML exception at my end. Please check the attached sample and update me whether I am missing something. If so, please modify it so that the undesired behavior is shown. In the meantime, what is the version of VisualStudio that you are testing with?

Regards,
Stefan Nenchev
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Tags
GridView
Asked by
Abhinav
Top achievements
Rank 1
Answers by
Abhinav
Top achievements
Rank 1
Stefan Nenchev
Telerik team
Share this question
or