C
C#2y ago
tom_gent

❔ MAUI custom content view only loads content correctly once

Hey I have created a MAUI custom control using handlers that uses MapContent to render content in a HorizontalScrollView (on android at least). The first time I set the content property through code or xaml, everything renders fine. The second time however, nothing is shown.
2 Replies
tom_gent
tom_gentOP2y ago
the content is mapped like this
public static void MapContent(CarouselScrollViewHandler handler, CarouselScrollView carouselScrollView)
{
_ = handler.PlatformView ?? throw new InvalidOperationException($"{nameof(PlatformView)} should have been set by base class.");
_ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
_ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

if (handler._mauiCarouselScrollView != null)
{
handler._mauiCarouselScrollView.RemoveAllViews();

if (carouselScrollView.Content != null)
{
View virtualContentView = (View)carouselScrollView.PresentedContent;
var contentView = virtualContentView.ToPlatform(handler.MauiContext);
handler._mauiCarouselScrollView.AddView(contentView);

contentView.Measure((int)virtualContentView.WidthRequest, (int)virtualContentView.HeightRequest);

contentView.RequestLayout();
contentView.Invalidate();

handler._mauiCarouselScrollView.RequestLayout();
handler._mauiCarouselScrollView.Invalidate();
}
}
}
public static void MapContent(CarouselScrollViewHandler handler, CarouselScrollView carouselScrollView)
{
_ = handler.PlatformView ?? throw new InvalidOperationException($"{nameof(PlatformView)} should have been set by base class.");
_ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
_ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

if (handler._mauiCarouselScrollView != null)
{
handler._mauiCarouselScrollView.RemoveAllViews();

if (carouselScrollView.Content != null)
{
View virtualContentView = (View)carouselScrollView.PresentedContent;
var contentView = virtualContentView.ToPlatform(handler.MauiContext);
handler._mauiCarouselScrollView.AddView(contentView);

contentView.Measure((int)virtualContentView.WidthRequest, (int)virtualContentView.HeightRequest);

contentView.RequestLayout();
contentView.Invalidate();

handler._mauiCarouselScrollView.RequestLayout();
handler._mauiCarouselScrollView.Invalidate();
}
}
}
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server