Share via

Image source in runtime

Dani_S 5,581 Reputation points
2024-08-11T12:05:47.1866667+00:00

Hi,

How i fill in view model this source.

Please supply the code, net 8 maui.

<Image Grid.Row="0" Grid.ColumnSpan="3" Source="{Binding LogoImage}" WidthRequest="250" HeightRequest="110" HorizontalOptions="Start" VerticalOptions="Center"/>

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
2024-08-12T05:46:32.17+00:00

Hello,

The Source property of the Image control in Maui corresponds to the ImageSource class. In ViewModel, you can refer to Load a local image to load Source in the following way.

private ImageSource logoImage;
public ImageSource LogoImage
{
    get
    {
        return logoImage;
    }
    set
    {
        if (logoImage != value)
        {
            logoImage = value;
            OnPropertyChanged(); // reports this property
        }
    }
}
//You can assign values ​​directly using the file path
LogoImage = "test.png";
LogoImage = ImageSource.FromFile("test.png");

// You can assign a value via a Uri, which is usually suitable for remote files.
LogoImage = ImageSource.FromUri(new Uri("https://aka.ms/campus.jpg"));

// If your image is a Stream read from a file, you can convert it to an ImageSource in this way;
LogoImage = Source = ImageSource.FromStream(() => your_file_stream);

Best Regards,

Alec Liu.


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.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dani_S 5,581 Reputation points
    2024-08-13T12:30:56.6966667+00:00

    You can close this ticket it Solved-:)

    Was this answer helpful?

    0 comments No comments

Your answer

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