Как обрабатывать изменение свойства Maui HandlerC#

Место общения программистов C#
Ответить
Гость
 Как обрабатывать изменение свойства Maui Handler

Сообщение Гость »

Я попытался преобразовать средство визуализации 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); }
}
}
Как добавить обработчик:

Код: Выделить всё

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»