XAML如何在图像上浮动文字

5
我有一些图片希望加上水印显示。 目前它们在一个stackpanel中,如下所示:
<StackPanel Orientation="Vertical"
                      Margin= "7,0,0,0" 
                      HorizontalAlignment="Center" >
            <Image Width="60"
                   Height="72"
                   VerticalAlignment="Top"
                   Margin="0 0 10 0"
                   Source="{Binding ImageToWatermark}" />

我应该使用什么XAML代码来在图片上浮动一个居中的文字?

例如,使用"Segoe Keycaps"字体在城市伦敦的图片上显示文字。

London

3个回答

5
使用 <Grid><Canvas> 替代 <StackPanel>,这样项目将会被绘制在彼此之上。

4

如果有帮助的话,我已经添加了一些示例代码。

<DataTemplate x:Key="ImageBackgroundBlackBorderedTextTemplate">
            <Grid Height="Auto" Margin="2,5,2,5">
                <Image Stretch="Fill" Source="{Binding ImageUrl}" />
                <Border Background="#80000000" VerticalAlignment="Bottom">
                    <TextBlock  Margin="5,2,5,2" TextWrapping="WrapWholeWords" Text="{Binding Title}"  Style="{StaticResource BaseTextBlockStyle}"/>
                </Border>
            </Grid>
        </DataTemplate>

0
在 Xamarin Forms 的情况下:
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Image
        x:Name="ml"
        Source="btn_LineType.png">
    </Image>
    <Label 
        HorizontalOptions="CenterAndExpand" 
        VerticalOptions="EndAndExpand" 
        Text="SomeText">
    </Label>
</Grid>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接