如何向DataGridTextColumn添加工具提示

时间:2022-01-21 20:34:09

I'm using WPFtoolkit DataGrid ,I have to wrap text in a DataGridTextColumn or I have to add a ToolTip to the text column. I have searched the net but i couldn't get a proper solution. Expecting your valuable suggestions...

我正在使用WPFtoolkit DataGrid,我必须在DataGridTextColumn中包装文本,或者必须向text列添加工具提示。我已经上网查了,但还是没找到合适的解决办法。期待你宝贵的建议……

2 个解决方案

#1


92  

Yes, you can add tooltip text to DataGridTextColumn - just stylize it

是的,您可以向DataGridTextColumn添加工具提示文本——只需对其进行样式化即可

<DataGridTextColumn Header="ScreenName" Binding="{Binding ScreenName}" >
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="ToolTip" Value="{Binding Name}" />
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

#2


16  

I'm not sure if you can add a tooltip to a DataGridTextColumn but you can easily use the DataGridTemplateColumn and the ToolTipService instead. e.g.

我不确定是否可以向DataGridTextColumn添加工具提示,但是可以轻松地使用DataGridTemplateColumn和ToolTipService。如。

<data:DataGrid.Columns>
    <data:DataGridTemplateColumn Header="Broker">
        <data:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Moniker.Abbreviation}"
                           ToolTipService.ToolTip="{Binding Moniker.Name}" />
            </DataTemplate>
        </data:DataGridTemplateColumn.CellTemplate>
    </data:DataGridTemplateColumn>
</data:DataGrid.Columns>

In this example Moniker.Abbreviation is displayed in the column. When the user hovers over a cell, the full broker name (Moniker.Name) is displayed in the tooltip.

在这个例子中绰号。在列中显示缩写。当用户悬停在单元格上时,在工具提示中显示完整的代理名(Moniker.Name)。

Note: This example was taken from a Silverlight 3.0 application.

注意:这个例子取自Silverlight 3.0应用程序。

#1


92  

Yes, you can add tooltip text to DataGridTextColumn - just stylize it

是的,您可以向DataGridTextColumn添加工具提示文本——只需对其进行样式化即可

<DataGridTextColumn Header="ScreenName" Binding="{Binding ScreenName}" >
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="ToolTip" Value="{Binding Name}" />
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

#2


16  

I'm not sure if you can add a tooltip to a DataGridTextColumn but you can easily use the DataGridTemplateColumn and the ToolTipService instead. e.g.

我不确定是否可以向DataGridTextColumn添加工具提示,但是可以轻松地使用DataGridTemplateColumn和ToolTipService。如。

<data:DataGrid.Columns>
    <data:DataGridTemplateColumn Header="Broker">
        <data:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Moniker.Abbreviation}"
                           ToolTipService.ToolTip="{Binding Moniker.Name}" />
            </DataTemplate>
        </data:DataGridTemplateColumn.CellTemplate>
    </data:DataGridTemplateColumn>
</data:DataGrid.Columns>

In this example Moniker.Abbreviation is displayed in the column. When the user hovers over a cell, the full broker name (Moniker.Name) is displayed in the tooltip.

在这个例子中绰号。在列中显示缩写。当用户悬停在单元格上时,在工具提示中显示完整的代理名(Moniker.Name)。

Note: This example was taken from a Silverlight 3.0 application.

注意:这个例子取自Silverlight 3.0应用程序。