I have a RadDocking
with panes, each one holding my custom object with unique DataContext.
For each pane I want to present a header with a ToolTip. Both the header and the ToolTip should be bound to some property of the pane's DataContext.
Hence I write something like this:
<UserControl.Resources>
<DataTemplate x:Key="DataTemplateTitleHeaderTooltip">
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerikDocking:RadPane}}, Path=Content.DataContext.TitleTootip}"
ToolTip="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerikDocking:RadPane}}, Path=Content.DataContext.TitleTootip}"
telerik:WindowHost.HitTestable="True" />
</DataTemplate>
</UserControl.Resources>
<telerikDocking:RadDocking>
<telerikDocking:RadDocking.DocumentHost>
<telerikDocking:RadSplitContainer>
<telerikDocking:RadPaneGroup>
<telerikDocking:RadPane HeaderTemplate="{StaticResource DataTemplateTitleHeaderTooltip}">
<Border x:Name="Target"
Background="HotPink" />
</telerikDocking:RadPane>
<telerikDocking:RadPane Header="Pane02">
<Border Background="Fuchsia" />
</telerikDocking:RadPane>
</telerikDocking:RadPaneGroup>
</telerikDocking:RadSplitContainer>
</telerikDocking:RadDocking.DocumentHost>
</telerikDocking:RadDocking>
While the "Target" has the following DataContext:
public class MyModel : DependencyObject
{
#region TitleTootip
/// <summary>
/// Gets or sets the tool tip for our model
/// </summary>
public string TitleTootip
{
get { return (string) GetValue(TitleTootipProperty); }
set { SetValue(TitleTootipProperty, value); }
}
/// <summary>
/// Identifies the <see cref="TitleTootip"/> property.
/// </summary>
public static readonly DependencyProperty TitleTootipProperty =
DependencyProperty.Register("TitleTootip", typeof (string), typeof (MyModel), new UIPropertyMetadata(""));
#endregion
}
This works fine when the pane is docked into a DocumentHost. However, when I detach the pane, both the the title and the ToolTip disappear.
Just to clarify, it will be really nice if the header and the ToolTip will appear not only in the docked state, but also once the window is floating.
A pure-xaml solution is definitely preferred.
You can use the Title
and TitleTemplate
properties of RadPane
to affect how the title of the ToolWindow
is templated. They are similar to Header
and HeaderTemplate
just used when the pane is floating.
Also, instead of using relative source from within the template of the header/title, supply the context/object that you need via binding at the window/UC level.
I've changed your sample and it works on my machine (i.e. I can see the title when the pane is floating):
<Window.Resources>
<DataTemplate x:Key="DataTemplateTitleWithTooltip">
<TextBlock Text="{Binding TitleTootip}"
ToolTip="{Binding TitleTootip}"
telerik:WindowHost.HitTestable="True"/>
</DataTemplate>
</Window.Resources>
<telerikDocking:RadDocking>
<telerikDocking:RadDocking.DocumentHost>
<telerikDocking:RadSplitContainer>
<telerikDocking:RadPaneGroup>
<telerikDocking:RadPane Header="{Binding RelativeSource={RelativeSource Self}, Path=Content.DataContext}"
HeaderTemplate="{StaticResource DataTemplateTitleWithTooltip}"
Title="{Binding RelativeSource={RelativeSource Self}, Path=Content.DataContext}"
TitleTemplate="{StaticResource DataTemplateTitleWithTooltip}">
<Border x:Name="Target"
Background="HotPink" />
</telerikDocking:RadPane>
<telerikDocking:RadPane Header="Pane02">
<Border Background="Fuchsia" />
</telerikDocking:RadPane>
</telerikDocking:RadPaneGroup>
</telerikDocking:RadSplitContainer>
</telerikDocking:RadDocking.DocumentHost>
</telerikDocking:RadDocking>
Notice that I pass the header/title the full data context of your content. Of course you can choose to pass only the relevant property.
Also, notice the line telerik:WindowHost.HitTestable="True"
in the data template. This is required for the text block to "feel" mouse over when it resides in the title of ToolWindow.