C
C#13mo ago
Yveske

No images in Android and IOS in contrast with same code in Windows

Given the following XAML both ImageBase64 (image from database) and ImageButton (image from resource via binding converter) are empty on Android and IOS.
<ContentPage.Resources>
<convert:Score___ToImageConverter x:Key="Score___ToImage" />
</ContentPage.Resources>

<Grid ... >
<CollectionView ItemsSource="{Binding Image___List}" ... >
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Imgext__">
<Grid x:Name="PicturesGrid">
<Frame ... >
<VerticalStackLayout>
<Frame .... >
<controls:ImageBase64 x:Name="MainImage"
Base64Source="{Binding Picture_}"
Aspect="AspectFit"
HorizontalOptions="Center"
VerticalOptions="Center">
</controls:ImageBase64>
</Frame>
<Frame .... >
<HorizontalStackLayout ... >
<ImageButton Source="{Binding Score___, Converter={StaticResource Score___ToImage}, ConverterParameter=0}" ... />
<ContentPage.Resources>
<convert:Score___ToImageConverter x:Key="Score___ToImage" />
</ContentPage.Resources>

<Grid ... >
<CollectionView ItemsSource="{Binding Image___List}" ... >
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Imgext__">
<Grid x:Name="PicturesGrid">
<Frame ... >
<VerticalStackLayout>
<Frame .... >
<controls:ImageBase64 x:Name="MainImage"
Base64Source="{Binding Picture_}"
Aspect="AspectFit"
HorizontalOptions="Center"
VerticalOptions="Center">
</controls:ImageBase64>
</Frame>
<Frame .... >
<HorizontalStackLayout ... >
<ImageButton Source="{Binding Score___, Converter={StaticResource Score___ToImage}, ConverterParameter=0}" ... />
ViewModel:
public partial class PicturesViewModel : BaseViewModel
{
public ObservableCollection <Imgext__> Image___List { get; } = new ();
...
}

public class Score___ToImageConverter : IValueConverter
{
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
{
string Result = "star_white.png";
...
return Result;
}

public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}

}
public partial class PicturesViewModel : BaseViewModel
{
public ObservableCollection <Imgext__> Image___List { get; } = new ();
...
}

public class Score___ToImageConverter : IValueConverter
{
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
{
string Result = "star_white.png";
...
return Result;
}

public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}

}
ImageBase64 (grabbed from the internet):
public class ImageBase64 : Microsoft.Maui.Controls.Image
{
public static readonly BindableProperty Base64SourceProperty =
BindableProperty.Create (nameof (Base64Source), typeof (string), typeof (ImageBase64), string.Empty, propertyChanged: OnBase64SourceChanged);

public string Base64Source
{
set { SetValue (Base64SourceProperty, value); }
get { return (string) GetValue (Base64SourceProperty); }
}

private static void OnBase64SourceChanged (BindableObject bindable, object oldValue, object newValue)
{
if (newValue != null)
{
MemoryStream stream = new MemoryStream (Convert.FromBase64String ((string) newValue));
((Image) bindable).Source = ImageSource.FromStream (() => stream);
}
else
{
((Image) bindable).Source = null;
}
}
}
public class ImageBase64 : Microsoft.Maui.Controls.Image
{
public static readonly BindableProperty Base64SourceProperty =
BindableProperty.Create (nameof (Base64Source), typeof (string), typeof (ImageBase64), string.Empty, propertyChanged: OnBase64SourceChanged);

public string Base64Source
{
set { SetValue (Base64SourceProperty, value); }
get { return (string) GetValue (Base64SourceProperty); }
}

private static void OnBase64SourceChanged (BindableObject bindable, object oldValue, object newValue)
{
if (newValue != null)
{
MemoryStream stream = new MemoryStream (Convert.FromBase64String ((string) newValue));
((Image) bindable).Source = ImageSource.FromStream (() => stream);
}
else
{
((Image) bindable).Source = null;
}
}
}
I'm using Visual Studio 2022 preview Version 17.8.0 Preview 7.0 on Windows. Tried the code on OnePlus Nord CE 3 lite (OxygenOS 13.1) , nVidia Shield tablet (Android 7.0) and IOS emulator (IPhone 15 IOS 17.0).
No description
No description
1 Reply
Yveske
YveskeOP13mo ago
Nobody ?
Want results from more Discord servers?
Add your server