[英]WPF XAML: place Image near TextBlock but align text to center of row
我在 WPF 應用程序中有類似的結構:
<Grid Background="White">
<StackPanel>
<TextBlock Text="1234567" FontSize="18" FontWeight="Bold" Height="25" TextAlignment="Center"/>
<Line X1="0" Y1="0" X2="160" Y2="0" Stroke="Gray" StrokeThickness="2"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Width="25" Height="25" Grid.Column="0" Source="img.png" />
<TextBlock Grid.Column="1" Text="3456789" FontSize="18" FontWeight="Bold" Height="25" TextAlignment="Center"/>
</Grid>
</StackPanel>
這導致以下布局:
有沒有辦法將底部文本放在行的中心,所以它的 alignment 會與上面的文本匹配? 或者有沒有解決方案將圖像放在左側底行的頂部而沒有列定義?
謝謝
使用具有不同對齊方式的單單元格網格。 您將冒着長文本位於圖像下方的風險,並且您必須在 StackPanel 上設置一個寬度值。 請參閱下面的HorizontalAlignment
標志:
<Grid>
<TextBlock Text="3456789" FontSize="18" FontWeight="Bold" Height="25" HorizontalAlignment="Center"/>
<Image Width="25" Height="25" Source="img.png" HorizontalAlignment="Left" />
</Grid>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.