将工具提示设置为相等的内容 [英] Setting tooltip to equal content

查看:76
本文介绍了将工具提示设置为相等的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将数据网格单元格的工具提示设置为等于该单元格中TextBlock内部的文本.到目前为止,我的情况是这样:

I'm trying to set a data grid's cell's tooltip to be equal to the text inside of a TextBlock in that cell. What I have so far is this:

<Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridCell">
                    <Grid>                         
                        <TextBlock Margin="2" VerticalAlignment="Center" 
                                HorizontalAlignment="Left"  TextWrapping="Wrap" >
                            <ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" />
                            <TextBlock.ToolTip>
                                <ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" />
                            </TextBlock.ToolTip>
                        </TextBlock>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>            
    </Style>

但是,此操作非常简短地显示了工具提示,然后删除了单元格中的内容,因此什么也没有显示.另外,可以从模板"设置器外部设置工具提示,但是我不确定执行此操作需要什么约束.

However, what this does is very briefly show the tooltip and then the content in the cell is removed, so nothing shows up at all. Also, setting the tooltip from outside the Template setter is an option, but I'm not sure what the corrent binding is to do that.

推荐答案

我的示例是一个简单的标签,但是可以将其应用于其他控件.

My example here is for a simple label but this can be applied to other controls.

<Label Name="lblFormName" Content="Form Elements:" FontWeight="Bold" HorizontalAlignment="Left" Width="295" >
                    <Label.ToolTip>
                        <Binding ElementName="lblFormName" Path="Content"/>
                    </Label.ToolTip>
                </Label>

查看此链接: http://msdn.microsoft.com/en -us/library/ms742167.aspx 或此链接为一堆来自MS http:/的绑定方法"的链接/msdn.microsoft.com/en-us/library/ms752039.aspx

Check out this link: http://msdn.microsoft.com/en-us/library/ms742167.aspx or this link for a bunch of binding "how-to"s from MS http://msdn.microsoft.com/en-us/library/ms752039.aspx

这篇关于将工具提示设置为相等的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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