我有一个FlipView
控制女巫,由图像和关于图像的文本组成。我希望文本与图像的宽度相同。一些图像的尺寸与其他图像不同。
这是我的 XAML 代码:
<FlipView x:Name="flipView" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" ItemsSource="{Binding ImagesWithDescriptions}">
<FlipView.ItemTemplate>
<DataTemplate>
<Grid x:Name="grid" Tapped="flipView_Tapped">
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition />
</Grid.RowDefinitions>
<Image x:Name="image" Grid.RowSpan="2" Source="{Binding Image}"></Image>
<Grid x:Name="textGrid" Grid.Row="1">
<Grid.Background>
<SolidColorBrush Color="Black" Opacity="0.5"/>
</Grid.Background>
<TextBlock Foreground="White" HorizontalAlignment="Left" FontSize="20" Text="{Binding Description}"/>
</Grid>
</Grid>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipViewControl>
如果我尝试将文本绑定到图像ActualWidth
,它总是返回 0。有没有办法做到这一点?
编辑:
它看起来像这样:
(-----------------FlipView 宽度----------------------) -------------------------------------------------- - - - F | |这是图像。它的高度是| |l | |等于 FlipView 的高度,| |我 | |但宽度取决于图片的| |p | |比率,可能在 | 上有所不同 |V | |一些图片。| |我 | | | |e | | | |w | | | | | | | |h | | | |e |---------|------------------|------- -----|我 |这是 |现在网格名为“textGrid”的位置(它是 |g |宽度与 FlipView 的相同) | |h -------------------------------------------------- ------t
但我希望Grid
命名为“textGrid”的宽度与 Image 的宽度相同。
绑定<Grid x:Name="textGrid" Width="{Binding ElementName=image, Path=ActualWidth}"/>
导致Grid
的宽度始终等于 0。Image Loaded 事件也返回ActualWidth
为 0。