HCL
HCL

Reputation: 36775

WPF prevent TextBlock from showing multiple lines without setting the height-property

I have a textblock within a GridView that is bound to a property that contains sometimes carriage returns in the text. How can I prevent the text-block showing more than one line of text? The only solution I have found is to set the height-property but this seems to me very unproper.

I expected the following declaration to do the trick, but it does not run. Maybe I have something forgotten?

<GridViewColumn Header="Info" >
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" Text="{Binding Info}"/>                                            
        </DataTemplate>                                    
    </GridViewColumn.CellTemplate>
</GridViewColumn>

Upvotes: 1

Views: 1064

Answers (1)

KBoek
KBoek

Reputation: 5975

One possible solution is to check the string for CR's before binding it to the TextBlock. Strip any \r and \n from the text.

Upvotes: 2

Related Questions