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

RadPane TitleTemplate with Button and custom event

6 Answers 204 Views
Docking
This is a migrated thread and some comments may be shown as answers.
JL
Top achievements
Rank 1
JL asked on 09 Apr 2014, 02:46 PM
 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.




6 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 14 Apr 2014, 10:25 AM
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.

 
0
JL
Top achievements
Rank 1
answered on 15 Apr 2014, 11:55 AM
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.

0
Accepted
Kalin
Telerik team
answered on 16 Apr 2014, 01:31 PM
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.

 
0
Charles
Top achievements
Rank 1
answered on 16 Apr 2014, 01:49 PM
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.

0
Konstantina
Telerik team
answered on 17 Apr 2014, 09:02 AM
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.

 
0
JL
Top achievements
Rank 1
answered on 17 Apr 2014, 07:09 PM
Hello everyone,

Kalin's solution works perfectly for me.

Thank you !
Tags
Docking
Asked by
JL
Top achievements
Rank 1
Answers by
Kalin
Telerik team
JL
Top achievements
Rank 1
Charles
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or