Clicking on a custom .NET MAUI Entry causing the screen to disapear

155 views Asked by At

I'm fairly new to .NET MAUI, and I'm taking an old, out of date Xamarin app that hasn't been touched in a few years and manually converting and updating it. I'm having an issue where a programmatically generated custom text entry is causing my screen to do the following when I click on it:

Before clicking on 'Volume Gas Vented'

A simple input screen

After clicking on 'Volume Gas Vented'

A blank screen

I've tried this on a few different emulators, and they all do the same

The whole form is programmatically generated, so just to keep it simple I'll specifically show the code for the 'Volume Gas Vented'

The code that generates it is:

View = new StackLayout
{
    Orientation = StackOrientation.Vertical,
    Padding = new Thickness(13, 5),
    Spacing = 0,
    VerticalOptions = LayoutOptions.FillAndExpand,
    Children =
    {
        new Label
        {
            Text = label,
            FontSize = Device.GetNamedSize (NamedSize.Micro, typeof(Label)),
            FontAttributes = FontAttributes.Bold,
        },
        CellType(type)
    }
}

I understand that LayoutOptions.FillAndExpand and Device.GetNamedSize are obsolete, and I've replaced them with either modern versions or something that should just be a simple value, or just replaced them altogether, but that has not fixed the issue

For the CellType function, it returns the following code:

var volumeGasVentedView = new GMSEntry
{
    Placeholder = "Enter",
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Keyboard = Keyboard.Numeric
};
volumeGasVentedView.SetBinding(Entry.TextProperty, "VolumeGasVented",     BindingMode.TwoWay, new DecimalConverter());
return new StackLayout
{
    Orientation = StackOrientation.Horizontal,
    Children =
    {
        volumeGasVentedView,
        new Label
        {
            HorizontalOptions = LayoutOptions.EndAndExpand,
            FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
            VerticalOptions = LayoutOptions.Center,
            Text = "scf"
        },
    }
};

The GMSEntry class is really simple and just expands on the Entry class

namespace MAUIGMSApp
{
    public class GMSEntry : Entry
    {
        public GMSEntry()
        {
            TextColor = Color.FromArgb("#000000");
        }
    }
}

And DecimalConverter is an additional custom class that implements the IValueConverter interface.

using System;
using System.Globalization;
    
namespace MAUIGMSApp
{
    class DecimalConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return String.Empty;
            decimal thedecimal = (decimal)value;
            thedecimal = Math.Round(thedecimal, 2, MidpointRounding.AwayFromZero);
            return thedecimal.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = value as string;
            if (string.IsNullOrEmpty(strValue))
                return null;
            if (decimal.TryParse(strValue, out decimal resultdecimal))
            {
                return resultdecimal;
            }
            return 0;
        }
    }
}

I've tried pairing it down to being the most bare bones, where it's this for the volume gas vented

var volumeGasVentedView = new Entry
{
    Placeholder = "Enter",
    Keyboard = Keyboard.Numeric
};
volumeGasVentedView.SetBinding(Entry.TextProperty, "VolumeGasVented", BindingMode.TwoWay);
return volumeGasVentedView;

But it still has the same issue. The datepicker and the select fields have no issue, it just seems to be something with the text fields. I assume its got something to do with something that was fine in Xamarin but not in MAUI, and I have a bad feeling its something obvious, what am I doing wrong here?

0

There are 0 answers