Need to add a radpathbutton RadGridView's searchpanel

1 Answer 55 Views
GridView Styling
Harshit
Top achievements
Rank 1
Harshit asked on 30 May 2022, 07:33 AM

hi Team,

I need to add a radpath button to the RadGridView's searchpanel .

RadGridView  doesnt has a particular style  property  for searchpanel, like it has for groups (i.e. GroupPaneItemStyle).

So I extracted the style, and to the control template added the radpath button.

But then this style is used globally in my application.  So this  button comes at  all  the places where the  RadGridView is used.

Now  I want to  add a attachproperty to the   radGridViewSearchPanel ,  which  can  be accessed from my different views and I should be able to control the  visibility  of my radpathbutton.

So I want something like this -

   

 <telerik:RadGridView
    Name="DeviceConnectionsGridView"
    ShowSearchPanel="True" 
    SearchPanelCloseButtonVisibility="Hidden"
My_AttachedProperty_For_SearchPanelsRadPathButtonVisbility =  "Visible"
/>

Here's what I performed -

I added an attached,  to  the GridViewSearchPanel class, but this property is only accessible where the GridViewSearchPanel is used.

In my case  ggridViewsearchpanel is  not  used directly but  coming from the  RadGridView, so this attach  property  is  not coming for R
adGridView.

So  plz  tell  me, how  can we  achieve  this ?


1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 31 May 2022, 08:44 AM

Hello Harshit,

To achieve this behavior, you could create a new attached property, and inside the property callback method, find the RadPathButton instance via the ChildrenOfType extension method. Then, modify the Visibility property of the returned element.

The following code snippets show a sample implementation of this attached property, as well as its use:

public class RadGridViewExtensions
{
    public static bool GetShouldButtonBeVisible(DependencyObject obj)
    {
        return (bool)obj.GetValue(ShouldButtonBeVisible);
    }

    public static void SetShouldButtonBeVisible(DependencyObject obj, bool value)
    {
        obj.SetValue(ShouldButtonBeVisible, value);
    }

    public static readonly DependencyProperty ShouldButtonBeVisible =
        DependencyProperty.RegisterAttached("ShouldButtonBeVisible",
            typeof(bool),
            typeof(RadGridViewExtensions),
            new PropertyMetadata(false, OnShouldShouldButtonBeVisibleChanged));

    private static void OnShouldShouldButtonBeVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        RadGridView radGridView = (RadGridView)d;

        radGridView.Loaded += (s, eventArgs) =>
        {
            var sender = (RadGridView)s;

            if (sender.ShowSearchPanel)
            {
                RadPathButton button = sender.ChildrenOfType<RadPathButton>().FirstOrDefault(x => x.Name == "CustomPathButton");

                if (button != null)
                {
                    if ((bool)e.NewValue)
                    {
                        button.Visibility = Visibility.Visible;
                    }
                }
            }
        };
    }
}
<telerik:RadGridView Name="grid1"
                     ShowSearchPanel="True"
                     local:RadGridViewExtensions.ShouldButtonBeVisible="True"/>
<telerik:RadGridView Name="grid2"
                     ShowSearchPanel="True"
                     local:RadGridViewExtensions.ShouldButtonBeVisible="False"/>

The produced result is as follows when set on the above-shared RadGridView instances:

I have also attached a sample project for you to test.

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView Styling
Asked by
Harshit
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or