зеркало из https://github.com/DeGsoft/maui-linux.git
98 строки
2.8 KiB
C#
98 строки
2.8 KiB
C#
using global::Windows.UI.Xaml;
|
|
using global::Windows.UI.Xaml.Automation.Peers;
|
|
|
|
namespace System.Maui.Platform.UWP
|
|
{
|
|
public class ViewRenderer<TElement, TNativeElement> : VisualElementRenderer<TElement, TNativeElement> where TElement : View where TNativeElement : FrameworkElement
|
|
{
|
|
string _defaultAutomationPropertiesName;
|
|
AccessibilityView? _defaultAutomationPropertiesAccessibilityView;
|
|
string _defaultAutomationPropertiesHelpText;
|
|
UIElement _defaultAutomationPropertiesLabeledBy;
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<TElement> e)
|
|
{
|
|
base.OnElementChanged(e);
|
|
|
|
if (e.NewElement != null)
|
|
{
|
|
UpdateBackgroundColor();
|
|
UpdateFlowDirection();
|
|
}
|
|
}
|
|
|
|
protected override void SetAutomationId(string id)
|
|
{
|
|
if (Control == null)
|
|
{
|
|
base.SetAutomationId(id);
|
|
}
|
|
else
|
|
{
|
|
this.SetAutomationPropertiesAutomationId($"{id}_Container");
|
|
Control.SetAutomationPropertiesAutomationId(id);
|
|
}
|
|
}
|
|
protected override void SetAutomationPropertiesName()
|
|
{
|
|
if (Control == null)
|
|
{
|
|
base.SetAutomationPropertiesName();
|
|
return;
|
|
}
|
|
|
|
_defaultAutomationPropertiesName = Control.SetAutomationPropertiesName(Element, _defaultAutomationPropertiesName);
|
|
}
|
|
|
|
protected override void SetAutomationPropertiesAccessibilityView()
|
|
{
|
|
if (Control == null)
|
|
{
|
|
base.SetAutomationPropertiesAccessibilityView();
|
|
return;
|
|
}
|
|
|
|
_defaultAutomationPropertiesAccessibilityView = Control.SetAutomationPropertiesAccessibilityView(Element, _defaultAutomationPropertiesAccessibilityView);
|
|
}
|
|
|
|
protected override void SetAutomationPropertiesHelpText()
|
|
{
|
|
if (Control == null)
|
|
{
|
|
base.SetAutomationPropertiesHelpText();
|
|
return;
|
|
}
|
|
|
|
_defaultAutomationPropertiesHelpText = Control.SetAutomationPropertiesHelpText(Element, _defaultAutomationPropertiesHelpText);
|
|
}
|
|
|
|
protected override void SetAutomationPropertiesLabeledBy()
|
|
{
|
|
if (Control == null)
|
|
{
|
|
base.SetAutomationPropertiesLabeledBy();
|
|
return;
|
|
}
|
|
|
|
if (Element == null)
|
|
return;
|
|
|
|
if (_defaultAutomationPropertiesLabeledBy == null)
|
|
_defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(global::Windows.UI.Xaml.Automation.AutomationProperties.LabeledByProperty);
|
|
|
|
var elemValue = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty);
|
|
var renderer = elemValue?.GetOrCreateRenderer();
|
|
var nativeElement = renderer?.GetNativeElement();
|
|
|
|
if (nativeElement != null)
|
|
Control.SetValue(global::Windows.UI.Xaml.Automation.AutomationProperties.LabeledByProperty, nativeElement);
|
|
else
|
|
Control.SetValue(global::Windows.UI.Xaml.Automation.AutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy);
|
|
}
|
|
|
|
void UpdateFlowDirection()
|
|
{
|
|
Control.UpdateFlowDirection(Element);
|
|
}
|
|
}
|
|
} |