I have been watching videos and looking up sample code but I am unable to figure out how to do this the right way.
[Porting custom renders to handlers]
(https://github.com/dotnet/maui/wiki/Porting-Custom-Renderers-to-Handlers) Now I have read the Assembly ExportRender has to be removed, found this in the above link. But the example does not match my code, not in a way I can link it together..
This is what worked in my Xamarin.Forms project:
using Android.Content;
using Android.Text;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(App.Views.NumericEntry), typeof(App.Android.NumericEntryRenderer))]
namespace App.Android
{
public class NumericEntryRenderer : EntryRenderer
{
public NumericEntryRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.InputType = InputTypes.ClassNumber | InputTypes.NumberFlagDecimal;
}
}
}
}
This is what I have now, which is not correct as I cannot find the 'OnElementChanged'
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Handlers;
using App.Controls.Interfaces;
using App.Views;
namespace App.Platforms.Android
{
public partial class NumericEntryHandler : ViewHandler<INumericEntry, NumericEntry>
{
public static PropertyMapper<INumericEntry, NumericEntry> NumericEntryMapper = new PropertyMapper<INumericEntry, NumericEntryHandler>(ViewHandler.ViewMapper)
{
[nameof(INumericEntry.Control)] = MapControl,
};
protected override NumericEntry CreatePlatformView()
{
return new NumericEntry(Context);
}
static void MapControl(NumericEntryHandler handler, INumericEntry entry)
{
handler.PlatformView.Control = entry.Control;
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.InputType = InputTypes.ClassNumber | InputTypes.NumberFlagDecimal;
}
}
}
}
If anyone could help me, this would be greatly appreciated as I cannot find anything elsewhere. Thanks