Setting TextTrimming (CharacterEllipsis) in DataGrid's Cell

Viewed 9176

I would like to apply TextTrimming property (CharacterEllipsis) to the text in WPF DataGrid cells.

DataGrid cells without TextTrimming set

I applied custom DataGridCell template as in this answer (code below) and it works well, except for the Hyperlink columns like the first one in the picture), which now are empty.

TextTrimming set on text columns, but hyperling column contents missing

<Style TargetType="DataGridCell">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Border Padding="3" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <ContentPresenter.ContentTemplate>
                            <DataTemplate>
                                <TextBlock TextTrimming="CharacterEllipsis" Text="{Binding Text}"/>
                            </DataTemplate>
                        </ContentPresenter.ContentTemplate>
                    </ContentPresenter>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I can see the difference in both column types in visual tree: Datagrid row in visual tree (when no custom template is applied)

but don't understand how I can use this information to apply TextTrimming to TextBlock's columns of both type. Thanks for your time ;)

1 Answers
Related