我有一个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>
而“目标”具有以下数据上下文:
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 解决方案。