Creating a Base Class for RadGridView using a ContextMenu

3 posts, 0 answers
  1. Abhinav
    Abhinav avatar
    17 posts
    Member since:
    Jun 2016

    Posted 07 Nov Link to this post

    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. Abhinav
    Abhinav avatar
    17 posts
    Member since:
    Jun 2016

    Posted 07 Nov in reply to Abhinav Link to this post

    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.

     

  3. UI for WPF is Visual Studio 2017 Ready
  4. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    280 posts

    Posted 09 Nov Link to this post

    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!
Back to Top