Define a default Control Panel for all my Gridview

6 posts, 0 answers
  1. Georges
    Georges avatar
    9 posts
    Member since:
    Feb 2014

    Posted 18 Feb 2015 Link to this post

      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
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 18 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Georges
    Georges avatar
    9 posts
    Member since:
    Feb 2014

    Posted 26 Feb 2015 in reply to Vanya Pavlova Link to this post

      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,



  5. Georges
    Georges avatar
    9 posts
    Member since:
    Feb 2014

    Posted 26 Feb 2015 in reply to Vanya Pavlova Link to this post

      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
  6. Clifford
    Clifford avatar
    3 posts
    Member since:
    Aug 2015

    Posted 23 Sep 2015 in reply to Vanya Pavlova Link to this post

    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.
  7. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 28 Sep 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready