0
votes

I make 5 column and 3 row grid.

ㅁㅁㅁㅁㅁ

ㅁㅁㅁㅁㅁ

ㅁㅁㅁㅁㅁ

And i add TextBlock (3 row, 1 column)

ㅁㅁㅁㅁㅁ

ㅁㅁㅁㅁㅁ

■ ㅁㅁㅁㅁ

However the TextBlock was placed in left top of (3, 1) grid. How i can set TextBlock in center of (3, 1) by code?

Grid gd=new Grid(); gd.HorizontalAlignment = HorizontalAlignment.Center; is not work.

What property i have to change? not xaml but code.

1

1 Answers

1
votes

you must apply the HorizontalAlignment.Center to the TextBlock not to the Grid :

TextBlock Tb=new TextBlock();

//...initialisation of the TextBlock

Tb.HorizontalAlignment = HorizontalAlignment.Center;