Я пытаюсь получить доступ к своему привязываемому свойству для пользовательской кнопки, для которой я пытаюсь закодировать средство визуализации.Сначала вот мой PCL-рендер:
public class BtnRenderer : Button
{
public static readonly BindableProperty HighLightProperty = BindableProperty.Create(nameof(HighlightedBackgroundColor), typeof(Color), typeof(BtnRenderer), default(Color));
public Color HighlightedBackgroundColor
{
get
{
return (Color)GetValue(HighLightProperty);
}
set
{
SetValue(HighLightProperty, value);
}
}
}
Как вы можете видеть, я намерен установить HighlightedBackgroundColor
из XAML, однако я не знаю, как получить к нему доступ в моем iOS-рендерере, что яhave is:
[assembly: ExportRenderer(typeof(BtnRenderer), typeof(BtnRendereriOS))]
namespace BluetoothExample.iOS
{
public class BtnRendereriOS : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var normalBackgroundColor = Element.BackgroundColor.ToUIColor();
var _highlightBackgroundColor = Element.HighlightedBackgroundColor.ToUIColor(); //HERE IS MY PROBLEM
async Task NormalColorState(UIButton button)
{
await UIView.TransitionNotifyAsync(button, .25, UIViewAnimationOptions.TransitionCrossDissolve, () =>
{
button.BackgroundColor = normalBackgroundColor;
});
}
Control.TouchDown += async (object sender, EventArgs c) =>
{
var button = sender as UIButton;
await UIView.TransitionNotifyAsync(button, .25, UIViewAnimationOptions.TransitionCrossDissolve, () =>
{
button.BackgroundColor = _highlightBackgroundColor;
});
};
}
}
}
Как мне получить доступ к этому свойству правильно?