Noah
Noah

Reputation: 15320

XAML how to float text over image

I have some images that I want to display with a watermark.

Currently they are within a stackpanel as follows:

<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}" />

What xaml would I use to float a centered text over an image?

For example, to display London over a picture of the city with this "Segoe Keycaps" font.

London

Upvotes: 5

Views: 6344

Answers (3)

user8942419
user8942419

Reputation:

In the case of 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>

Upvotes: 0

W.K.S
W.K.S

Reputation: 10095

I've added some sample code in case it helps.

<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>

Upvotes: 4

elder_george
elder_george

Reputation: 7879

Use <Grid> or <Canvas> instead of <StackPanel> and items will be drawn upon each other.

Upvotes: 5

Related Questions