2013-04-08 41 views
5

我試圖在視覺上align 2(或更多)塊的內容的頂部Text。 每個塊的內容和FontSize,Family,Weight)可以由用戶修改。垂直對齊WPF文本塊的頂部

我試圖玩GetCellAscent,GetCellDescentGetLineSpacing功能,但結果只取決於字體而不是真正的內容。無論如何,我無法找到如何分配LineSpacingAscent+ Descent之間的差異在塊的頂部和底部。

比如我想生產這種輸出:

enter image description here

任何幫助嗎?

+0

你就不能加 'VerticalAlignment = 「頂」' 的文本塊元素? – Deruijter 2013-04-08 09:39:23

+0

你應該向我們展示你的代碼(在這種情況下是xaml):用這種方式,我們可以幫助你更簡單 – 2013-04-08 09:41:33

+0

@Daniele Armanasco:這是純代碼,不需要顯示XAML。 – user2223898 2013-04-08 09:45:36

回答

1

試試這個.....

<Grid Width="171" Height="100" Background="Black" Margin="257,78,75,133"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto" /> 
      <ColumnDefinition Width="Auto" /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 

     </Grid.RowDefinitions> 

     <TextBlock Name="aaa" Text="12" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Stretch" Grid.Row="1" FontWeight="Bold" Foreground="White" /> 
     <TextBlock Text="$" HorizontalAlignment="Left" FontSize="20" Grid.Column="1" FontFamily="Euphemia" FontWeight="Bold" Foreground="White" Margin="8,0,72,0" /> 
     <TextBlock Text="00 le Kg" FontSize="15" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Left" Grid.IsSharedSizeScope="True" FontFamily="Euphemia" FontWeight="Bold" Foreground="White"/> 

    </Grid> 
+0

我可能不夠清楚,但我的問題是將「12」塊的頂部與「$」(或「€」或其他)塊的頂部對齊。這對於任何字體家族/大小/重量... – user2223898 2013-04-09 13:49:10

+0

看到編輯版本,並更改​​textblock aaa的字體大小以查看更改...現在是ri8嗎? – YOusaFZai 2013-04-10 08:47:35

+0

(對不起,這麼晚回答,我沒有收到變更通知)我知道可以手動對齊兩個文本塊內容。但我想自動完成。 – user2223898 2013-04-16 09:12:02