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

Find parent RadPane of visual element

2 Answers 194 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 01 Oct 2014, 06:04 PM
I added a new button to my pane header (a 'help' button) using the following link: http://www.telerik.com/help/silverlight/raddocking-how-to-add-buttons-to-the-pane-headers.html

I also created a custom routed ui command using the following link: http://www.telerik.com/help/silverlight/raddocking-how-to-add-menu-items-to-the-radpanes-menu.html

However, I had some trouble finding the RadPane containing the clicked RadButton in the pane header. I'm sure there is a much better or simpler way to find the current pane. Here is my solution, but could someone tell me what the proper method is?

Template attached to RadPane:

 <DataTemplate x:Key="TitleTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ContentPresenter Content="{Binding}"
                          Margin="0,0,10,0" />
            <telerik:RadButton Style="{StaticResource helpButton}" Grid.Column="1" HorizontalAlignment="Right"
                               Command="common:HelpCommand.OpenHelpTooltipCommand" CommandParameter="{Binding}" CommandTarget="{Binding}">
                <Image Style="{StaticResource imghelpButton}" />
            </telerik:RadButton>
        </Grid>
    </DataTemplate>

Registered command:

CommandManager.RegisterClassCommandBinding(typeof(RadButton),
                new CommandBinding(HelpCommand.OpenHelpTooltipCommand, HelpCommand.OnOpenHelpTooltip, HelpCommand.OnOpenHelpTooltipCanExecute));

Custom command:

    public static class HelpCommand
    {
        private static RoutedUICommand openHelpTooltipCommand;

        public static RoutedUICommand OpenHelpTooltipCommand
        {
            get
            {
                if (openHelpTooltipCommand == null)
                {
                    openHelpTooltipCommand = new RoutedUICommand("Open help tooltip", "OpenHelpTooltipCommand", typeof(HelpCommand));
                }
                return openHelpTooltipCommand;
            }
        }

        public static void OnOpenHelpTooltip(object sender, ExecutedRoutedEventArgs e)
        {
            var btn = e.OriginalSource as RadButton;
            if (btn != null)
            {
                var parent = btn.GetVisualParent<Telerik.Windows.Controls.Docking.ToolWindow>();
                if (parent != null)
                {
                    var docking = parent.GetParentDocking();
                    if (docking != null)
                    {
                        foreach (var pane in docking.Panes)
                        {
                            if ((string)pane.Title == (string)btn.DataContext)
                            {
                                var control = pane.Content; //THERE MUST BE A BETTER WAY TO GET HERE!!!
                            }
                        }
                    }
                }
            }
        }

        public static void OnOpenHelpTooltipCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
    }

2 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 02 Oct 2014, 10:16 AM
Hi Eddie,

Thank you for contacting us.

The easiest approach in getting the RadPane instance by an element in it's TitleTemplate is to used the PaneHeader element of that template and use it's GetParentPane() method. The next code snippet shows how the OnOpenHelpTooltip method from your code snippet should look like:

using Telerik.Windows.Controls.Docking;
...
 
public static void OnOpenHelpTooltip(object sender, ExecutedRoutedEventArgs e)
{
    var btn = e.OriginalSource as RadButton;
    if (btn != null)
    {
        var paneHeader = btn.ParentOfType<PaneHeader>();
        if (paneHeader != null)
        {
            var pane = paneHeader.GetParentPane();
        }
    }
}

Hope this is helpful.

Regards,
Vladi
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ben
Top achievements
Rank 1
answered on 02 Oct 2014, 05:26 PM
Thanks Vladi!

Your solution actually did not work correctly for me, but it helped lead me to another one that did:

http://www.telerik.com/forums/radpane-titletemplate-with-button-and-custom-event#wKMKSmkTBEeiuwM6VF8y8A

Apparently if the RadPane is floating or docked, it takes a different method to access it from the TitleTemplate
Tags
Docking
Asked by
Ben
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Ben
Top achievements
Rank 1
Share this question
or