I have three classes involved in my problem. PopupView, CardView, and TestPopup. PopupView represents a base class for popups, and uses CardView, to display 3 ContentView linerally with header body and footer. TestPopup inherits PopupView which itself exposes a Body property that sets the CardView Body property with the latter.
Please note that PopupView and CardView are in a sepparate class library, it seems to matter because if I define TestPopup in the class library everything works fine. So at this point I think either I am doing something horribly wrong or there is a bug maybe someone is aware of in MAUI.
Here is the code:
<tt:PopupView
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:tt="http://barambibol.io/dotnet/maui/timertoolkit"
x:Class="TestApp.PopupTest"
>
<tt:PopupView.Body>
<Label Text="AAA"/>
</tt:PopupView.Body>
</tt:PopupView>
public partial class PopupTest : PopupView
{
public PopupTest()
{
InitializeComponent();
}
}
public partial class PopupView : PopupBase
{
public PopupView()
{
InitializeComponent();
}
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (width != -1 && height != -1)
{
// Here cardView is null. bodyContentView however is not null.
cardView.WidthRequest = width * TimerToolkitConfig.PopupPageWidthRatio;
cardView.MinimumHeightRequest = TimerToolkitConfig.ConfirmationPopupContentHeight;
cardView.MaximumHeightRequest = height * TimerToolkitConfig.PopupPageHeightRatioMax;
bodyContentView.Content = Body;
}
}
}
Here when I try to access an element from the view in code-behind, one of them is null. It is “cardView”. “bodyContentView”, which is a child of “cardView”, is not null. How is that even possible ? Any light on this would be greatly appreciated I honestyl have absolutely no clue how this can happen