我有一个包含两行两列的网格。
在 0,0 的位置我放置了一个 TextBlock,其中的文本因本地化而异。在 1,0 的位置我放置了一张图片。
以下是 XAML 示例:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="Tb" Grid.Row="0" Grid.Column="0">Foobar</TextBlock>
<Image Source="Foobar.jpg" Grid.Row="1" Grid.Column="0" />
</Grid>
</Window>
我需要网格列#0的宽度与TextBlock文本一样宽。 图像应与列的宽度相同,并且其高度应正确设置以保持纵横比例。
我尝试将图像包装在NoSizeDecorator中,但这样做图像根本不会出现,除非我在XAML中指定图像的绝对高度和宽度,但我无法这样做,因为我需要图像与文本的宽度相同。
我该怎么办?
Stretch="Uniform"
是默认值,因此无需显式设置。 - Clemens