我有一个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 width----------------------) --------------------------------------------------------F | |This is Image. It's height is | |l | |equals to FlipView's height, | |i | |but width depends on picture's| |p | |ratio, which might differ on | |V | |some pictures. | |i | | | |e | | | |w | | | | | | | |h | | | |e |----------|------------------------------|------------|i |This is |where Grid named "textGrid" is|now (it's |g |width is |the same as FlipView's) | |h --------------------------------------------------------t
但我希望名为“textGrid”的Grid
具有与Image相同的宽度
绑定<Grid x:Name="textGrid" Width="{Binding ElementName=image, Path=ActualWidth}"/>
导致Grid
的宽度始终等于0. Image Loaded事件也将ActualWidth
返回为0。
答案 0 :(得分:0)
def calculate_volume(self): return averager( self.nodes, 'get_compartment_volume')
def get_contraction(self): return averager( self.branches, 'get_contraction' )