aks*_*000 0 xaml winrt-xaml windows-10 uwp
我有一个Image
控制绑定到一个源.这就是我想要的:
Stretch="None"
.Stretch="Uniform"
.我试图将MaxWidth和MaxHeight绑定到父级的实际尺寸,如下所示:
<DataTemplate x:Key="ImageDataTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Title}" Grid.Row="0"/>
<TextBlock Text="{Binding Type}" Grid.Row="1"/>
<Grid x:Name="ImageWrapper" Grid.Row="1" Tapped="ImageWrapper_Tapped" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="AliceBlue">
<Image Source="{Binding Link}" MaxWidth="{Binding ActualWidth, ElementName=ImageWrapper}" MaxHeight="{Binding ElementName=ImageWrapper, Path=ActualHeight}"/>
</Grid>
</Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
但是,我最终根本没有图像.从背景颜色可以看出,父网格占据了所有可用空间.但是没有形象.
有没有办法实现我想要的行为?
将图像放入Viewbox控件并将Viewbox设置StretchDirection
为DownOnly
.Stretch
Viewbox 的属性具有默认值Uniform
,因此您无需进行设置.
<Viewbox StretchDirection="DownOnly">
<Image Source="{Binding Link}" Stretch="None"/>
</Viewbox>
Run Code Online (Sandbox Code Playgroud)
也许值得注意的是,在WPF中你可以直接设置StretchDirection
Image控件,因此不需要Viewbox.
<Image Source="{Binding Link}" StretchDirection="DownOnly"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1672 次 |
最近记录: |