Thanks for reading into my issue.
I just started working with C# MAUI MVVM and ran into the following issue:
DetailPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp2.DetailPage"
xmlns:viewmodel="clr-namespace:MauiApp2.ViewModel"
x:DataType="viewmodel:DetailViewModel"
Title="DetailPage">
<VerticalStackLayout Padding="20">
<Label
Text="{Binding Text}"
FontSize="25"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button Text="Go Back" Command="{Binding GoBackCommand}" />
<Image Source="{Binding Uri.normal}"/>
</VerticalStackLayout>
</ContentPage>
DetailViewModel.cs
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MauiApp2.Model;
namespace MauiApp2.ViewModel
{
[QueryProperty("Text", "Text")]
[QueryProperty("Normal", "Normal")]
[QueryProperty("ImageUris.normal", "ImageUris.normal")]
public partial class DetailViewModel : ObservableObject
{
[ObservableProperty]
string text;
[ObservableProperty]
string normal;
[ObservableProperty]
Cards_Root.ImageUris uri;
[RelayCommand]
async Task GoBack()
{
await Shell.Current.GoToAsync("..");
}
}
}
Used Classes from Cards_Root look like this
public class Cards_Root
{
public ImageUris image_uris { get; set; }
}
public class ImageUris
{
public string small { get; set; }
public string normal { get; set; }
public string large { get; set; }
public string png { get; set; }
public string art_crop { get; set; }
public string border_crop { get; set; }
}
The Binding of “Text” on the Label in DetailPage works fine, but the Source of the Image stays empty and I cant figure out why. First thought it might be because of the name of the Variable, but Visual Studio even highlights it as using “Uri” as ImageUris Class and “normal” as string.
Thanks a lot in Advance!
Ferrumaniac is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.