Put and Image and Text on a label control in .NET Maui

Fritz Switzer 321 Reputation points
2023-07-26T00:22:14.7666667+00:00

I'm not seeing my background image and text displayed in a .NET Maui app. Here is it code I used in an UWP app that worked that I am trying to convert to a .NET Maui app.

 <StackPanel Grid.Column="1" Margin="0,148,0,71" Grid.Row="2" Tapped="StackPanel_Tapped" Grid.RowSpan="2">
        <StackPanel.Background>
            <ImageBrush ImageSource="Assets/blueindex.jpg"/>
        </StackPanel.Background>
        <TextBlock x:Name="Answer1" TextWrapping="Wrap" Text="TextBlock" Margin="0,0,0,0" Foreground="Black" Height="210" TextAlignment="Center" FontSize="26.667" />
    </StackPanel>


Here is the code I'm using, but no Text is displayed in my .NET Maui app but the image is displayed.

 <StackLayout Grid.Column="1" Grid.Row="5" Grid.RowSpan="2">
        <StackLayout.GestureRecognizers>
            <TapGestureRecognizer Tapped="StackLayout_Tapped" />
        </StackLayout.GestureRecognizers>
        <Image Source="blueindex.jpg" />
        <Label x:Name="Answer2" Text="TextBlock" TextColor="Black" FontSize="26.667" VerticalTextAlignment="Center" HeightRequest="210" />
    </StackLayout>

What are some recommended changes to my .NET Maui code?

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-07-26T01:45:49.3866667+00:00

    Hello,

    You can use Gird to warp the Image and Label, then you can implement Text on the Image effect like the following code.

       <StackLayout Grid.Column="1" Grid.Row="5" Grid.RowSpan="2">
            <StackLayout.GestureRecognizers>
                <TapGestureRecognizer Tapped="StackLayout_Tapped" />
            </StackLayout.GestureRecognizers>
    
            <Grid>
                <Image Source="blueindex.jpg" />
                <Label x:Name="Answer2" Text="TextBlock" TextColor="Black" FontSize="26.667" VerticalTextAlignment="Center" HeightRequest="210" />
            </Grid>
            
        </StackLayout>
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.