maui-linux/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs

61 строка
1.3 KiB
C#
Исходник Обычный вид История

2016-03-22 23:02:25 +03:00
using System.ComponentModel;
using Android.Views;
namespace Xamarin.Forms.Platform.Android
{
public class BoxRenderer : VisualElementRenderer<BoxView>
{
bool _isInViewCell;
2016-03-22 23:02:25 +03:00
public BoxRenderer()
{
AutoPackage = false;
}
public override bool OnTouchEvent(MotionEvent e)
{
if (base.OnTouchEvent(e))
return true;
return !Element.InputTransparent && !_isInViewCell;
2016-03-22 23:02:25 +03:00
}
protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var parent = e.NewElement.Parent;
while (parent != null)
{
if (parent is ViewCell)
{
_isInViewCell = true;
break;
}
parent = parent.Parent;
}
}
2016-03-22 23:02:25 +03:00
UpdateBackgroundColor();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == BoxView.ColorProperty.PropertyName || e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
UpdateBackgroundColor();
}
protected override void UpdateBackgroundColor()
2016-03-22 23:02:25 +03:00
{
Color colorToSet = Element.Color;
if (colorToSet == Color.Default)
colorToSet = Element.BackgroundColor;
SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent));
}
}
}