Моя карта Handler для Android:
Код: Выделить всё
public static void Map(IElementHandler handler, IElement view)
{
if (view is CustomEntry)
{
var control = (EntryHandler)handler;
var viewData = (CustomEntry)view;
var gd = new GradientDrawable();
gd.SetColor(viewData.BackgroundColor.ToAndroid());
gd.SetCornerRadius((int)handler.MauiContext?.Context.ToPixels(viewData.CornerRadius));
gd.SetStroke((int)handler.MauiContext?.Context.ToPixels(viewData.BorderThickness), viewData.BorderColor.ToAndroid());
control.PlatformView?.SetBackground(gd);
var padTop = (int)handler.MauiContext?.Context.ToPixels(viewData.Padding.Top);
var padBottom = (int)handler.MauiContext?.Context.ToPixels(viewData.Padding.Bottom);
var padLeft = (int)handler.MauiContext?.Context.ToPixels(viewData.Padding.Left);
var padRight = (int)handler.MauiContext?.Context.ToPixels(viewData.Padding.Right);
control.PlatformView?.SetPadding(padLeft, padTop, padRight, padBottom);
}
}
How the controls properties are added:
public class CustomEntry : Entry
{
public static readonly BindableProperty PlaceholderFontSizeProperty =
BindableProperty.Create(nameof(PlaceholderFontSize), typeof(double), typeof(CustomEntry), -1d);
public static BindableProperty CornerRadiusProperty =
BindableProperty.Create(nameof(CornerRadius), typeof(int), typeof(CustomEntry), 0);
public static BindableProperty BorderThicknessProperty =
BindableProperty.Create(nameof(BorderThickness), typeof(int), typeof(CustomEntry), 0);
public static BindableProperty PaddingProperty =
BindableProperty.Create(nameof(Padding), typeof(Thickness), typeof(CustomEntry), new Thickness(5));
public static BindableProperty BorderColorProperty =
BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(CustomEntry), Colors.Transparent);
public int CornerRadius
{
get => (int)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}
public int BorderThickness
{
get => (int)GetValue(BorderThicknessProperty);
set => SetValue(BorderThicknessProperty, value);
}
public Color BorderColor
{
get => (Color)GetValue(BorderColorProperty);
set => SetValue(BorderColorProperty, value);
}
///
/// This property cannot be changed at runtime in iOS.
///
public Thickness Padding
{
get => (Thickness)GetValue(PaddingProperty);
set => SetValue(PaddingProperty, value);
}
public double PlaceholderFontSize
{
get { return (double)GetValue(PlaceholderFontSizeProperty); }
set { SetValue(PlaceholderFontSizeProperty, value); }
}
}
Код: Выделить всё
Microsoft.Maui.Handlers.ElementHandler.ElementMapper.AppendToMapping(nameof(CustomEntry), (handler, view) =>
{
if (view is CustomEntry)
{
CustomEntryMapper.Map(handler, view);
}
});
Подробнее здесь: https://stackoverflow.com/questions/781 ... ty-changed