Telerik RadDocking在浮动窗口标题上显示ToolTip

时间:2013-06-05 23:23:19

标签: wpf xaml data-binding telerik raddocking

我有一个带有窗格的RadDocking,每个窗格都使用唯一的DataContext保存我的自定义对象。 对于每个窗格,我想使用工具提示呈现标题。标题和工具提示都应绑定到窗格的DataContext的某些属性。

因此我写了这样的话:

<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>

虽然“Target”具有以下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
}

当窗格停靠在DocumentHost中时,此工作正常。但是,当我分离窗格时,标题和工具提示都会消失。

为了澄清一下,如果标题和工具提示不仅会出现在停靠状态,而且一旦窗口浮动,那将会非常好。

纯xaml溶液绝对是首选。

1 个答案:

答案 0 :(得分:0)

您可以使用Title的{​​{1}}和TitleTemplate属性来影响RadPane的标题的模板化方式。它们类似于窗格浮动时使用的ToolWindowHeader

此外,不是在标题/标题的模板中使用相对源,而是通过窗口/ UC级别的绑定提供所需的上下文/对象。

我已经更改了你的样本,它可以在我的机器上运行(即,当窗格浮动时我可以看到标题):

HeaderTemplate

请注意,我将标题/标题传递给您内容的完整数据上下文。当然,您可以选择只传递相关的财产。

另外,请注意数据模板中的行<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> 。当文本块位于ToolWindow的标题中时,这是“感觉”鼠标悬停所必需的。