Automatic handler for all instances of RadGridView

3 posts, 0 answers
  1. Mark
    Mark avatar
    9 posts
    Member since:
    Oct 2014

    Posted 04 May Link to this post

    I have some functionality that I would like to have included in every instance of RadGridView in my application. This is on two events, DistinctValuesLoading and FilterOperatorsLoading.

     

    I tried adding them via EventSetters in a global Style ResourceDictionary, but I'm getting error saying that they are not Routed Events.

     

    Is  there another way to do this, or do I need to just add the functionality manually to every instance?

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    347 posts

    Posted 05 May Link to this post

    Hi Mark,

    Before I dive in my answer, I wanted to briefly touch on the fact the you're not assigned a license for UI for WPF (trial or paid). The license policy is that every dev using the product should be assigned a license.

    It a very common scenario that a company will purchase the licenses, but forget to assign them to the developers. this will prevent you from submitting support tickets and be forced to use the public forum (support tickets carry a guaranteed 24 hour response from one of the engineers).

    It only takes about 20 seconds to assign you the license and can be done online here in the Manage Licensed Users portal (they use your email address to assign you the license).

    Okay, onto my answer!


    Solution

    You can accomplish this by creating a custom behavior and hooking into the event there.  In addition, because you want this to be applied globally, you can set your custom behavior in an Implicit style. 

    I have written you a small example to better explain this.  Open it and go to the following locations:


    1 - Go to App.xaml

    Start in App.xaml, you'll see I've defined an implicit style for RadGridView. This style will inherit all of the setters for the default GridView style because I am using "BasedOn".  It will implicitly be applied to all of the application's GridViews because I did not set an x:Key and the set TargetType.

    Take note of the attached property "IsEnabled", that will be attached to all of your GridViews.


    2 - Go to MyBehavior.cs

    Find this in the Behaviors folder. You'll see that it's a behavior designed just for a RadGridView. So you'll have access to all of the properties of the GridView when it's attached via the "AssociatedObject" property. This is where you can hook into the event handler you want, it doesn't have to be a RoutedEvent.


    3 - Go to AttachablePropForBehavior.cs

    Find this in the Behaviors folder. This is the mechanism that allows this to work in a Style Setter. By setting IsEnabled = "True" in the Style, your custom behavior will be added to the RadGridView.


    4 - Go to MainPage.xaml

    You'll see there are two RadGridViews. Neither of them have any defines event handlers there.


    5 - Finally, run the demo

    Run the demo and make you can see your Debug Output window. When you open any of the column filters, you'll see the debug output show the event handler were hit.


    Here's a screenshot at runtime:




    If you still have trouble, please open a support ticket here so that one of the engineers can dig in deeper.

    Thank you for contacting Phone Assistance and for choosing UI for WPF.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Mark
    Mark avatar
    9 posts
    Member since:
    Oct 2014

    Posted 05 May in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Thank you. I see how to do it now.
Back to Top