我不知道我完全理解你的問題的限制,所以它可能是這些方法都將工作,但這裏的兩個快速的建議。 (就個人而言,我喜歡解決方案2更好。)
<Edit: Additional Thought>
解決方案0
如果你能夠改變文本塊的Grid.ColumnSpan
,你可以做的解決方案2,而該容器。只需將文本塊跨越幾列,並調整文本塊的填充以將內容居中!
</Edit>
解決方案1
首先,如果您當前的XAML結構看起來是這樣的:
<Grid>
<TextBlock Grid.Column="2" Text="12345" />
</Grid>
考慮將其更改爲這樣的事情?
<Grid>
<!-- Draw up columns so that the textblock looks as you wish -->
<TextBlock Grid.Column="2" Text="12345" />
<!-- Span an inner grid across all the columns/rows in the outer grid -->
<Grid Grid.ColumnSpan=".."
Grid.RowSpan="..">
<!-- All the other stuff in the Grid -->
</Grid>
</Grid>
解決方案2
如果不能正常工作,考慮住房另一容器中的文本塊,如Label
,並跨越跨列。
<Grid>
<!-- Use the left/right padding on the label to center the textbox -->
<sdk:Label Grid.Column="0"
Grid.ColumnSpan="3"
Grid.Row="1"
HorizontalAlignment="Center"
Padding="13,0,0,0">
<!-- In my example, setting the left pading to 13 centered the textbox -->
<TextBlock HorizontalAlignment="Center"
Text="......!......" />
<!-- Text like the test above, really helped find the correct padding -->
</sdk:Label>
</Grid>
我希望這個作品的限制之內,如果沒有,可以幫助你找出自己的解決方案!
你真的給它一些思考謝謝,病態標記爲答案,如果沒有更好的想法在幾天 – 2011-05-31 19:55:36