仅在选项卡名称上使用WPF工具提示 [英] WPF ToolTip only on tab name

查看:72
本文介绍了仅在选项卡名称上使用WPF工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我想要做的只是在标签名称上显示工具提示(如在浏览器中),而不是在整个标签网格上。我搜索了谷歌,但我没有发现任何有趣的东西。知道怎么做吗?

解决方案

你可能在Tab上设置它而不是标题。请尝试使用标题。这可能需要您重新设置标题。

您可以根据需要重新设置标题,然后为用于显示标题的UI元素设置工具提示。



这样的东西应该可以工作。



注意:这没有经过测试,所以可能会有错误。



 <   TabControl     x:名称  =   tabCtrlMain    ItemsSource  < span class =code-keyword> =  {Binding Items}   >  
< TabControl.Resources >
< 样式 TargetType = TabItem >
< Setter 属性 = 标题 = {Binding FileName} / >
< Setter < span class =code-attribute>属性 = HeaderTemplate >
< Setter.Value < span class =code-keyword>>
< DataTemplate DataType = {x:Type TabItem} >
< 边框 x:名称 = grid >
< ContentPresenter >
< ContentPresenter.Content >
< TextBlock 文字 = {TemplateBinding Content} 工具提示 = {Binding Path = TooltInfo} / >
< span class =code-keyword>< / ContentP resenter.Content >
< / ContentPresenter >
< / Border >
< / DataTemplate >
< < span class =code-leadattribute> / Setter.Value >
< / Setter >
< ; / Style >
< / TabControl.Resources >
< / TabControl >





如果您直接在XAML中添加标签,那么只需向标题开始编码。



ie



 <  < span class =code-leadattribute> TabItem  >  
< TabItem.Header >
< 网格 >
< Grid.ToolTip >
<! - 将工具提示内容放在此处 - >
< / Grid.ToolTip >

< / Grid >
< ; / TabItem.Header >

< / TabItem >


Hi!
what I''m trying to do is showing tool tip only on tab name (like in browsers), not on whole tab grid. I''ve searched Google but i have not found nothing interesting. Any idea how to do that?

解决方案

You are likely setting it on the Tab not the header. Try the header instead. This may require you to restyle the header.
You can restyle the header how ever you want though and then set the tooltip for the UI element you use to display the header.

Something like this should work.

Note: this was not tested so there may be errors in it.

<TabControl x:Name="tabCtrlMain" ItemsSource="{Binding Items}" >
        <TabControl.Resources>
            <Style TargetType="TabItem">
                <Setter Property="Header" Value="{Binding FileName}" />
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate DataType="{x:Type TabItem}">
                            <Border x:Name="grid">
                                    <ContentPresenter>
                                        <ContentPresenter.Content>
                                            <TextBlock Text="{TemplateBinding Content}" Tooltip="{Binding Path=TooltInfo}"/>
                                        </ContentPresenter.Content>
                                    </ContentPresenter>
                                </Border>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </TabControl.Resources>
    </TabControl>



If you are directly adding tabs in XAML then just code right to the header.

i.e.

<TabItem>
    <TabItem.Header>
        <Grid>
            <Grid.ToolTip>
                <!--Place your tooltip content here-->
            </Grid.ToolTip>

        </Grid>
    </TabItem.Header>

</TabItem>


这篇关于仅在选项卡名称上使用WPF工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆