user3351509
user3351509

Reputation: 25

WPF: how centre textBlock in Grid Column if Text is longer that Row width

I have a Grid with 5 columns of Width 160 each. I want a TextBlock (which Width is longer than Columns Width) to be at the centre-top of the window (let say in Centre of Column 2(3rd Col) and that the parts of text that exceeds the Column Width is shown in both rows beside. I tried HorizontalAlignment="Center", Canvas, RenderTransformOrigin, and other ways I searched, but doesn't work. Thanks in advance

Upvotes: 0

Views: 878

Answers (1)

rejy11
rejy11

Reputation: 752

I'm not exactly sure what you're asking, but I think you want the TextBlock to be visible along multiple columns? If so, set the Grid.ColumnSpan property on the TextBlock to 2.

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="160"/>
            <ColumnDefinition Width="160"/>
            <ColumnDefinition Width="160"/>
            <ColumnDefinition Width="160"/>
            <ColumnDefinition Width="160"/>
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Column="2"
                   Grid.ColumnSpan="2"
                   HorizontalAlignment="Center"
                   Text="Hello"/>

</Grid>

Upvotes: 1

Related Questions