Я попытался преобразовать средство визуализации xam в Hadler Maui, и у меня все заработало, за исключением изменения свойства моих пользовательских элементов управления. В моем пользовательском элементе управления при изменении цвета границы он не обновляется в представлении. Как мне с этим справиться?
Моя карта 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); }
}
}
Я попытался преобразовать средство визуализации xam в Hadler Maui, и у меня все заработало, за исключением изменения свойства моих пользовательских элементов управления. В моем пользовательском элементе управления при изменении цвета границы он не обновляется в представлении. Как мне с этим справиться? Моя карта Handler для Android: [code] public static void Map(IElementHandler handler, IElement view) { if (view is CustomEntry) { var control = (EntryHandler)handler; var viewData = (CustomEntry)view;
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);
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); } } } [/code] Как добавить обработчик: [code]Microsoft.Maui.Handlers.ElementHandler.ElementMapper.AppendToMapping(nameof(CustomEntry), (handler, view) => { if (view is CustomEntry) { CustomEntryMapper.Map(handler, view); } }); [/code] Есть идеи, как заставить его обновляться при обновлении свойств настраиваемых элементов управления?