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

Define a default Control Panel for all my Gridview

5 Answers 162 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Georges
Top achievements
Rank 1
Georges asked on 18 Feb 2015, 10:07 AM
  Hello,

I would like to define in a style a default control panel (with a button to export the grid as excel/pdf/etc...) for all my RadGridView, but I can't figure out how to set the ControlPanelItems in a style.
Is this possible ? and if so, how can I do?

Thanks in advance for your help.

Regards

5 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 18 Feb 2015, 01:07 PM
Hello Georges,


ControlPanelItems property of the grid is not a dependency property. To be used in XAML mark-up, it must be exposed on the target type with an accessible instance property, ControlPanelItems.
Thinking in this way, it' s not possible to define a style targeted at RadGridView and set ControlPanelItems globally for all grid view elements. 

I recommend you to set these items on particular instance of the grid. 
Hope this helps. 


Regards,
Vanya Pavlova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Georges
Top achievements
Rank 1
answered on 26 Feb 2015, 03:28 PM
  Hello,

Thanks for your reply. I found a workaround by writing a behavior (see code below)

public class RadGridViewBehavior
   {
       private const string _ToolTipExportMenu = "Exporter";
 
       public static readonly DependencyProperty ShowExportMenuProperty =
           DependencyProperty.RegisterAttached("ShowExportMenu", typeof(bool), typeof(RadGridViewBehavior), new UIPropertyMetadata(ShowExportMenuChanged));
 
       public static void SetShowExportMenu(UIElement element, bool value)
       {
           element.SetValue(ShowExportMenuProperty, value);
       }
 
       public static bool GetShowExportMenu(UIElement element)
       {
           return (bool)element.GetValue(ShowExportMenuProperty);
       }
 
       private static void ShowExportMenuChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
       {
           if (e.NewValue == e.OldValue)
               return;
 
           RadGridView grid = target as RadGridView;
           if (grid != null)
           {
               bool val = (bool)e.NewValue;
               if (val)
               {
                   ControlPanelItem cp = new ControlPanelItem();
                   object resIcon = Application.Current.TryFindResource("IcoExportSmall");
                   if (resIcon != null)
                   {
                       cp.ButtonContent = resIcon;
                       cp.ButtonTooltip = _ToolTipExportMenu;
                       cp.Content = new GridMenuExporterUC();
                       grid.ControlPanelItems.Add(cp);
                   }
               }
               else
               {
                   var item = grid.ControlPanelItems.FirstOrDefault(c => c.ButtonTooltip == _ToolTipExportMenu);
                   if (item != null)
                       grid.ControlPanelItems.Remove(item);
               }
           }
       }
     
   }

Regards,



0
Georges
Top achievements
Rank 1
answered on 26 Feb 2015, 03:30 PM
  Hello Vanya,

Thanks for your reply. I found a workaround making a Behavior. see code below :

public class RadGridViewBehavior
   {
       private const string _ToolTipExportMenu = "Exporter";
 
       public static readonly DependencyProperty ShowExportMenuProperty =
           DependencyProperty.RegisterAttached("ShowExportMenu", typeof(bool), typeof(RadGridViewBehavior), new UIPropertyMetadata(ShowExportMenuChanged));
 
       public static void SetShowExportMenu(UIElement element, bool value)
       {
           element.SetValue(ShowExportMenuProperty, value);
       }
 
       public static bool GetShowExportMenu(UIElement element)
       {
           return (bool)element.GetValue(ShowExportMenuProperty);
       }
 
       private static void ShowExportMenuChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
       {
           if (e.NewValue == e.OldValue)
               return;
 
           RadGridView grid = target as RadGridView;
           if (grid != null)
           {
               bool val = (bool)e.NewValue;
               if (val)
               {
                   ControlPanelItem cp = new ControlPanelItem();
                   object resIcon = Application.Current.TryFindResource("IcoExportSmall");
                   if (resIcon != null)
                   {
                       cp.ButtonContent = resIcon;
                       cp.ButtonTooltip = _ToolTipExportMenu;
                       cp.Content = new GridMenuExporterUC();
                       grid.ControlPanelItems.Add(cp);
                   }
               }
               else
               {
                   var item = grid.ControlPanelItems.FirstOrDefault(c => c.ButtonTooltip == _ToolTipExportMenu);
                   if (item != null)
                       grid.ControlPanelItems.Remove(item);
               }
           }
       }
 
   }


Regards
0
Clifford
Top achievements
Rank 1
answered on 23 Sep 2015, 05:57 PM
First of all I would recommend that there be a way to do this since this is something that would be good to be globally defined. Is there any recommendation on how to at least have some of these elements defined in a central place.
0
Yoan
Telerik team
answered on 28 Sep 2015, 02:28 PM
Hello Clifford,

I am afraid that there is no easy way for achieving this functionality at the moment. However, we will take this into account, while planning our next release.

Regards,
Yoan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Georges
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Georges
Top achievements
Rank 1
Clifford
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or