以下文本块按预期包装和修剪.修剪文本时会显示省略号"...".
<TextBlock
MaxWidth="60"
MaxHeight="60"
Text="This is some long text which I would like to wrap."
TextWrapping="Wrap"
TextTrimming="CharacterEllipsis" />
Run Code Online (Sandbox Code Playgroud)
我想用全文显示文本上的工具提示,但仅限于文本被修剪.我不确定如何可靠地确定是否显示"...".
如何确定文本是否正在修剪?
在 Windows 应用商店应用程序中,我有以下 TextBlock:
<TextBlock Text="Seriously long text for the purpose of showing tooltip"
TextTrimming="CharacterEllipsis" />
Run Code Online (Sandbox Code Playgroud)
当文本太长而无法在没有省略号的情况下显示时,如何自动显示工具提示?
我的应用程序使用 C# 和 WPF(.net framework 4.0)运行。我的目标是拥有一个 DataGrid,其中单元格中的文本被省略号修剪,并且只有当单元格中的文本被实际修剪时才会自动显示带有完整文本的工具提示。
解决方案 1:我目前正在使用它来了解文本是否被修剪:http : //tranxcoder.wordpress.com/2008/10/12/customizing-lookful-wpf-controls-take-2/ 问题是它仅在我调整列大小时才有效。首次加载 DataGrid、对列进行排序或更新 DataGrid 的 ItemSource 时,不会显示工具提示。
解决方案 2:我也试过这个:http : //www.scottlogic.com/blog/2011/01/31/automatically-showing-tooltips-on-a-trimmed-textblock-silverlight-wpf.html 但是工具提示永远不会出现在我的 DataGrid 单元格上,但它可以很好地处理孤立的文本块。
我正在寻找简单的方法来改进解决方案 1 并使其在所有情况下都能在我的 DataGrid 中工作,或者可能采用不同的方法。
解决方案 1 的样式:
<UserControl.Resources>
<Style x:Key="TextColumnElementStyle" TargetType="TextBlock" BasedOn="{StaticResource TextBlockService}">
<Style.Setters>
<Setter Property="TextWrapping" Value="NoWrap" />
<Setter Property="TextTrimming" Value="WordEllipsis" />
</Style.Setters>
</Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
解决方案 1 的 DataGrid:
<DataGrid ItemsSource="{Binding IssueList}" tbs:TextBlockService.AutomaticToolTipEnabled="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Description" Binding="{Binding Description}"
ElementStyle="{StaticResource TextColumnElementStyle}">
</DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
谢谢