maui-linux/System.Maui.Platform.UAP/LayoutRenderer.cs

75 строки
1.8 KiB
C#
Исходник Постоянная ссылка Обычный вид История

2020-05-19 03:56:25 +03:00
using System.ComponentModel;
using global::Windows.Foundation;
using global::Windows.UI;
using global::Windows.UI.Xaml;
using global::Windows.UI.Xaml.Automation.Peers;
using global::Windows.UI.Xaml.Media;
2016-03-22 23:02:25 +03:00
2020-05-19 03:56:25 +03:00
namespace System.Maui.Platform.UWP
2016-03-22 23:02:25 +03:00
{
public class LayoutRenderer : ViewRenderer<Layout, FrameworkElement>
{
protected override void OnElementChanged(ElementChangedEventArgs<Layout> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
SizeChanged -= OnSizeChanged;
SetAutomationId(null);
2016-03-22 23:02:25 +03:00
}
if (e.NewElement != null)
{
SizeChanged += OnSizeChanged;
UpdateClipToBounds();
if (!string.IsNullOrEmpty(Element.AutomationId))
{
SetAutomationId(Element.AutomationId);
}
}
}
protected override void UpdateBackgroundColor()
{
base.UpdateBackgroundColor();
if (GetValue(BackgroundProperty) == null && Children.Count == 0)
{
// Forces the layout to take up actual space if it's otherwise empty
Background = new SolidColorBrush(Colors.Transparent);
2016-03-22 23:02:25 +03:00
}
}
protected override AutomationPeer OnCreateAutomationPeer()
{
// Since layouts in Forms can be interacted with, we need to create automation peers
// for them so we can interact with them in automated tests
return new FrameworkElementAutomationPeer(this);
}
2016-03-22 23:02:25 +03:00
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == Layout.IsClippedToBoundsProperty.PropertyName)
UpdateClipToBounds();
}
void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
UpdateClipToBounds();
}
void UpdateClipToBounds()
{
Clip = null;
if (Element.IsClippedToBounds)
{
Clip = new RectangleGeometry { Rect = new Rect(0, 0, ActualWidth, ActualHeight) };
}
}
}
}