Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,28 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con
return _defaultAutomationPropertiesAccessibilityView;
}

bool isInitializing = (Element.Handler as ElementHandler)?._isInitializing ?? false;

AccessibilityView? currentValue = null;

if (!_defaultAutomationPropertiesAccessibilityView.HasValue)
if (isInitializing)
{
currentValue = AccessibilityView.Content;
_defaultAutomationPropertiesAccessibilityView ??= AccessibilityView.Content;
}
else
{
_defaultAutomationPropertiesAccessibilityView = currentValue = (AccessibilityView)Control.GetValue(NativeAutomationProperties.AccessibilityViewProperty);
if (!_defaultAutomationPropertiesAccessibilityView.HasValue)
{
_defaultAutomationPropertiesAccessibilityView = currentValue = (AccessibilityView)Control.GetValue(NativeAutomationProperties.AccessibilityViewProperty);
}
}

var newValue = _defaultAutomationPropertiesAccessibilityView;

var elemValue = (bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty);
var elemValue = isInitializing
? null
: (bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty);

if (elemValue == true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ static void DetermineTruncatedTextWrapping(TextBlock textBlock) =>

public static void UpdateText(this TextBlock platformControl, Label label)
{
bool isFirstAssignment = (label.Handler as ElementHandler)?._isInitializing ?? false;

switch (label.TextType)
{
case TextType.Html:
Expand All @@ -32,13 +34,16 @@ public static void UpdateText(this TextBlock platformControl, Label label)

default:
if (label.FormattedText != null)
{
platformControl.UpdateInlines(label);
}
else
{
if (platformControl.TextHighlighters.Count > 0)
if (!isFirstAssignment && platformControl.TextHighlighters.Count > 0)
{
platformControl.TextHighlighters.Clear();
}

platformControl.Text = TextTransformUtilites.GetTransformedText(label.Text, label.TextTransform);
}
break;
Expand Down Expand Up @@ -67,7 +72,9 @@ public static void UpdateMaxLines(this TextBlock platformControl, Label label)
public static void UpdateDetectReadingOrderFromContent(this TextBlock platformControl, Label label)
{
if (label.IsSet(Specifics.DetectReadingOrderFromContentProperty))
{
platformControl.SetTextReadingOrder(label.OnThisPlatform().GetDetectReadingOrderFromContent());
}
}

internal static void SetLineBreakMode(this TextBlock textBlock, LineBreakMode lineBreakMode, int? maxLines = null)
Expand Down
18 changes: 17 additions & 1 deletion src/Core/src/Handlers/Element/ElementHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ protected ElementHandler(IPropertyMapper mapper, CommandMapper? commandMapper =

public IElement? VirtualView { get; private protected set; }

/// <summary><see langword="true"/> when view's properties are being set through its mapper for the first time, <see langword="false"/> otherwise.</summary>
internal bool _isInitializing;

public virtual void SetMauiContext(IMauiContext mauiContext) =>
MauiContext = mauiContext;

Expand All @@ -47,10 +50,21 @@ public virtual void SetVirtualView(IElement view)
bool setupPlatformView = oldVirtualView == null;

VirtualView = view;
PlatformView ??= CreatePlatformElement();

bool isNew = false;

if (PlatformView is null)
{
PlatformView = CreatePlatformElement();
isNew = true;
}

_isInitializing = isNew;

if (VirtualView.Handler != this)
{
VirtualView.Handler = this;
}

// We set the previous virtual view to null after setting it on the incoming virtual view.
// This makes it easier for the incoming virtual view to have influence
Expand All @@ -77,6 +91,8 @@ public virtual void SetVirtualView(IElement view)
}

_mapper.UpdateProperties(this, VirtualView);

_isInitializing = false;
}

public virtual void UpdateValue(string property)
Expand Down
6 changes: 5 additions & 1 deletion src/Core/src/Handlers/View/ViewHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ internal static void MapContextFlyout(IElementHandler handler, IContextFlyoutEle
}
else
{
uiElement.ClearValue(UIElement.ContextFlyoutProperty);
bool? skipInitialization = (handler as ElementHandler)?._isInitializing ?? false;
if (skipInitialization != true)
{
uiElement.ClearValue(UIElement.ContextFlyoutProperty);
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Core/src/Handlers/View/ViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,10 @@ public static void MapUnfocus(IViewHandler handler, IView view, object? args)
/// <param name="view">The associated <see cref="IView"/> instance.</param>
public static void MapToolTip(IViewHandler handler, IView view)
{
#if PLATFORM
#if WINDOWS
if (view is IToolTipElement tooltipContainer)
handler.ToPlatform().UpdateToolTip(tooltipContainer);
#elif PLATFORM
if (view is IToolTipElement tooltipContainer)
handler.ToPlatform().UpdateToolTip(tooltipContainer.ToolTip);
#endif
Expand Down
31 changes: 27 additions & 4 deletions src/Core/src/Platform/Windows/TextBlockExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Xml.Linq;
using System.Xml.Resolvers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;

namespace Microsoft.Maui.Platform
{
Expand All @@ -31,12 +30,36 @@ public static void UpdateText(this TextBlock platformControl, ILabel label)
public static void UpdateTextColor(this TextBlock platformControl, ITextStyle text) =>
platformControl.UpdateProperty(TextBlock.ForegroundProperty, text.TextColor);

public static void UpdatePadding(this TextBlock platformControl, ILabel label) =>
platformControl.UpdateProperty(TextBlock.PaddingProperty, label.Padding.ToPlatform());
public static void UpdatePadding(this TextBlock platformControl, ILabel label)
{
var padding = label.Padding;

bool? skipInitialization = (label.Handler as ElementHandler)?._isInitializing ?? false
|| padding != Thickness.Zero;

if (skipInitialization != true)
{
platformControl.UpdateProperty(TextBlock.PaddingProperty, padding.ToPlatform());
}
}

public static void UpdateCharacterSpacing(this TextBlock platformControl, ITextStyle label)
{
platformControl.CharacterSpacing = label.CharacterSpacing.ToEm();
var characterSpacing = label.CharacterSpacing.ToEm();

if (label is ILabel realLabel)
{
bool skipInitialization = (realLabel.Handler as ElementHandler)?._isInitializing ?? false && characterSpacing == 0;

if (!skipInitialization)
{
platformControl.CharacterSpacing = characterSpacing;
}
}
else
{
platformControl.CharacterSpacing = characterSpacing;
}
}

public static void UpdateTextDecorations(this TextBlock platformControl, ILabel label)
Expand Down
9 changes: 7 additions & 2 deletions src/Core/src/Platform/Windows/TransformationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ public static void UpdateTransformation(this FrameworkElement frameworkElement,
if (rotationX % 360 == 0 && rotationY % 360 == 0 && rotation % 360 == 0 &&
translationX == 0 && translationY == 0 && scaleX == 1 && scaleY == 1)
{
frameworkElement.Projection = null;
frameworkElement.RenderTransform = null;
bool? skipInitialization = (view.Handler as ElementHandler)?._isInitializing ?? false;

if (skipInitialization != true)
{
frameworkElement.Projection = null;
frameworkElement.RenderTransform = null;
}
}
else
{
Expand Down
Loading