-
-
Save myd7349/ac6ec27a0add63140f5c9e206a6a8061 to your computer and use it in GitHub Desktop.
WPF datagrid tooltip for hidden text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TrimmedTextBlockVisibilityConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | |
{ | |
if (value == null) return Visibility.Collapsed; | |
FrameworkElement textBlock = (FrameworkElement)value; | |
textBlock.Measure(new System.Windows.Size(Double.PositiveInfinity, Double.PositiveInfinity)); | |
if (((FrameworkElement)value).ActualWidth < ((FrameworkElement)value).DesiredSize.Width) | |
return Visibility.Visible; | |
else | |
return Visibility.Collapsed; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<DataGrid.Resources> | |
<Style TargetType="{x:Type DataGridCell}"> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="{x:Type DataGridCell}"> | |
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}" TextTrimming="CharacterEllipsis"> | |
<TextBlock.ToolTip> | |
<ToolTip Visibility="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget, Converter={StaticResource TrimToVisConverter}}"> | |
<ToolTip.Content> | |
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}"/> | |
</ToolTip.Content> | |
</ToolTip> | |
</TextBlock.ToolTip> | |
</TextBlock> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
</DataGrid.Resources> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment