RadPane TitleTemplate with Button and custom event

7 posts, 1 answers
  1. JL
    JL avatar
    4 posts
    Member since:
    Apr 2014

    Posted 09 Apr 2014 Link to this post

     Hi,

    I'm trying to add a button to the TitleTemplate of RadPanes (beside the Pin), handle the click event on this button and display a message specific to the targeted RadPanel.
    So far, I've applied the solution presented here: http://blogs.telerik.com/xamlteam/posts/09-08-19/customizing-the-header-of-radpane-control-and-adding-behavior-to-it.aspx

    My DataTemplate (in Resources):

    <Window.Resources>
            <DataTemplate x:Key="PaneHelpHeaderTemplate">
                    <StackPanel Orientation="Horizontal">
                        <ContentPresenter Content="{Binding}"
                              Margin="0,0,0,0" />
                    <telerik:RadButton   Content="Help" view:HelpButton.IsHelp="True" />
                    </StackPanel>
            </DataTemplate>
    </Window.Resources>

    Applied to:
    <telerik:RadPane Name="radPaneTOC" IsPinned="True" CanUserClose="False" CanDockInDocumentHost="False" CanUserPin="False" TitleTemplate="{StaticResource PaneHelpHeaderTemplate}">

    And my custom property definition (which is basically a Copy-Paste of the reference above) :   
    public static class HelpButton
    {
        public static readonly DependencyProperty IsHelp = DependencyProperty.RegisterAttached("IsHelp", typeof(bool), typeof(Telerik.Windows.Controls.RadButton), new PropertyMetadata(OnIsHelpButtonChanged));
     
     
        public static bool GetIsHelp(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsHelp);
        }
     
        public static void SetIsHelp(DependencyObject obj, bool value)
        {
            obj.SetValue(IsHelp, value);
        }
     
        private static void OnIsHelpButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
            bool oldValue = (bool)e.OldValue;
            bool newValue = (bool)e.NewValue;
            var button = d as ButtonBase;
     
            if (button != null && oldValue != newValue)
            {
                if (!oldValue && newValue)
                {
                    button.Click += OnCloseButtonClick;
                }
                else
                {
                    button.Click -= OnCloseButtonClick;
                }
            }
        }
     
     
        private static void OnCloseButtonClick(object sender, RoutedEventArgs args)
        {
             
     
            var button = sender as FrameworkElement;
     
            if (button != null)
            {
             // NONE OF THEM WORK
                var pane = button.ParentOfType<RadPane>();
              //  var pane = button.GetVisualParent<RadPane>();
              //  var pane = ((System.Windows.Controls.StackPanel)button.Parent).Parent;
                if (pane != null)
                {
                    Console.WriteLine("Parent found");
                }
            }
        }
    }


    As mentioned in the comment, I can't access to the parent (always null), which would allow me to get its Help content (custom property) (or do anything else with it).

    I'm not sure if that is the good approach, I heard and read a little about custom Commands (here), but I'm not very familiar with the process. 

    As a side note, I would like to define the visibility and the content (text) of this button programmatically.

    Thank you,

    JL.




  2. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 14 Apr 2014 Link to this post

    Hello JL,

    Thank you for contacting us.

    The Panes have different templates depending on their current state, that is why you cannot get the Pane the same way it was done when it was docked in the DocumentHost. In the case when the Pane is docked outside of the DocumentHost you should find the PaneHeader and get the targeted RadPane through it. Please check the modified code of the button click handler (check the Output Window):

    private static void OnCloseButtonClick(object sender, RoutedEventArgs args)
    {
        var button = sender as FrameworkElement;
     
        if (button != null)
        {
            var paneHeader = button.ParentOfType<PaneHeader>();
            var pane = paneHeader.GetParentPane();
                    
            if (pane != null)
            {
                Debug.WriteLine("Parent found - " + pane.Name);
            }
        }
    }

    Hope this will work for you.

    Regards,
    Kalin
    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. JL
    JL avatar
    4 posts
    Member since:
    Apr 2014

    Posted 15 Apr 2014 Link to this post

    Hi,

    Thanks for this. According to what you said, this solution would work only if the panel is in a particular state (docked outside a DocumentHost). Therefore, it seems that, if the panel is floating, the ParentOfType<PaneHeader> returns null and the panel not accessible. Considering that a panel state might change during the execution of the application, is there a solution that would work at any time ? My goal is simply to display a different message (RadWindow) depending of the location of the icon that has been clicked.

    I'm trying to avoid to create a DataTemplate, with a different event listener, for each panel, but if it's the most reliable solution at this point I'll go for it.

    Thanks,

    JL.

  5. Answer
    Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 16 Apr 2014 Link to this post

    Hi JL,

    In order to achieve the desired behavior you should check whether the Pane has ParentOfType PaneHeader for Pane docked outside of the DocumentHost, RadPane for Pane docked in the DocumentHost and ToolWindow for the floating Pane case. So the method should look as shown below:

    private static void OnCloseButtonClick(object sender, RoutedEventArgs args)
    {
        var button = sender as FrameworkElement;
     
        if (button != null)
        {
            // not in the DocumentHost
            var paneHeader = button.ParentOfType<PaneHeader>();
            if (paneHeader != null)
            {
                var pane = paneHeader.GetParentPane();
                Debug.WriteLine("Pane found - " + pane.Name);
            }
     
            // in the DocumentHost
            var paneInDocumentHost = button.ParentOfType<RadPane>();
            if (paneInDocumentHost != null)
            {
                Debug.WriteLine("Pane found - " + paneInDocumentHost.Name);
            }
     
            // floating Pane
            var toolWindow = button.ParentOfType<ToolWindow>();
            if (toolWindow != null)
            {
                var pane = toolWindow.FindChildByType<RadPane>();
                Debug.WriteLine("Pane found - " + pane.Name);
            }
        }
    }


    Hope this will help you to achieve the required.

    Regards,
    Kalin
    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.

     
  6. Charles
    Charles avatar
    10 posts
    Member since:
    Dec 2011

    Posted 16 Apr 2014 in reply to Kalin Link to this post

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane
    http://www.telerik.com/forums/controls-inside-a-raddocumentpane
    http://www.telerik.com/forums/controls-inside-a-raddocumentpane
    http://www.telerik.com/forums/controls-inside-a-raddocumentpane
    http://www.telerik.com/forums/controls-inside-a-raddocumentpane
    http://www.telerik.com/forums/controls-inside-a-raddocumentpane
    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    http://www.telerik.com/forums/controls-inside-a-raddocumentpane

    answer please.

  7. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 17 Apr 2014 Link to this post

    Hello Charles,

    I have already answered your question in the other forum post. If you need quicker response you could always open a support ticket. I suggest to continue the conversation in the topic related thread.

    Regards,
    Konstantina
    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.

     
  8. JL
    JL avatar
    4 posts
    Member since:
    Apr 2014

    Posted 17 Apr 2014 in reply to Kalin Link to this post

    Hello everyone,

    Kalin's solution works perfectly for me.

    Thank you !
Back to Top
UI for WPF is Visual Studio 2017 Ready