I am making an app using .NET MAUI and I am trying to implement custom handlers for specific instances of controls (ex. some entries should use a custom handler I created). To achieve this I followed the official MS docs for this. The following is the setup they tell me to use:
1.First make a subclass of the Entry control:
using Microsoft.Maui.Controls;
namespace MyMauiApp
{
public class MyEntry : Entry
{
}
}
2.I then customize the EntryHandler to perform the desired modification to MyEntry instances:
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
namespace MauiApp1
{
public partial class App : Application
{
public App()
{
InitializeComponent();
Microsoft.Maui.Handlers.EntryHandler.EntryMapper[nameof(IView.Background)] = (handler, view) =>
{
if (view is MyEntry)
{
#if __ANDROID__
handler.NativeView.SetBackgroundColor(Colors.Red.ToNative());
#elif __IOS__
handler.NativeView.BackgroundColor = Colors.Red.ToNative();
handler.NativeView.BorderStyle = UIKit.UITextBorderStyle.Line;
#elif WINDOWS
handler.NativeView.Background = Colors.Red.ToNative();
#endif
}
};
}
}
}
PROBLEM: This gives me the following error:
Severity Code Description Project File Line Suppression State Error CS0021 Cannot apply indexing with [] to an expression of type 'IPropertyMapper<IEntry, EntryHandler>' MyMauiApp (net6.0-android), MyMauiApp (net6.0-ios), MyMauiApp (net6.0-windows10.0.19041) C:\Users\xxxxxx\source\repos\MyMauiApp\MyMauiApp\App.xaml.cs 24 Active
As I said I followed the docs completely but still this error. I have read that other people have this issue too. Can anyone help?