diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs
index 731110a9ed7e..d0b5ac652ef3 100644
--- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs
+++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs
@@ -159,7 +159,7 @@ internal partial class Inner : DependencyObject
partial class OuterClass
{
[global::Microsoft.UI.Xaml.Data.Bindable]
- partial class Inner : IDependencyObjectStoreProvider, ITemplatedParentProvider, IWeakReferenceProvider
+ partial class Inner : IDependencyObjectStoreProvider, IWeakReferenceProvider
{
private DependencyObjectStore __storeBackingField;
public global::Windows.UI.Core.CoreDispatcher Dispatcher => global::Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;
@@ -185,28 +185,6 @@ private DependencyObjectStore __Store
public object GetAnimationBaseValue(DependencyProperty dp) => __Store.GetAnimationBaseValue(dp);
public long RegisterPropertyChangedCallback(DependencyProperty dp, DependencyPropertyChangedCallback callback) => __Store.RegisterPropertyChangedCallback(dp, callback);
public void UnregisterPropertyChangedCallback(DependencyProperty dp, long token) => __Store.UnregisterPropertyChangedCallback(dp, token);
-
- [EditorBrowsable(EditorBrowsableState.Never)]private ManagedWeakReference _templatedParentWeakRef;
- [EditorBrowsable(EditorBrowsableState.Never)]public ManagedWeakReference GetTemplatedParentWeakRef() => _templatedParentWeakRef;
-
- [EditorBrowsable(EditorBrowsableState.Never)]public DependencyObject GetTemplatedParent() => _templatedParentWeakRef?.Target as DependencyObject;
- [EditorBrowsable(EditorBrowsableState.Never)]public void SetTemplatedParent(DependencyObject parent)
- {
- //if (parent != null)
- //{
- // global::System.Diagnostics.Debug.Assert(parent
- // is global::Windows.UI.Xaml.Controls.Control
- // or global::Windows.UI.Xaml.Controls.ContentPresenter
- // or global::Windows.UI.Xaml.Controls.ItemsPresenter);
- // global::System.Diagnostics.Debug.Assert(GetTemplatedParent() == null);
- //}
-
- SetTemplatedParentImpl(parent);
- }
- [EditorBrowsable(EditorBrowsableState.Never)]private protected virtual void SetTemplatedParentImpl(DependencyObject parent)
- {
- _templatedParentWeakRef = (parent as IWeakReferenceProvider)?.WeakReference;
- }
private readonly static IEventProvider _binderTrace = Tracing.Get(DependencyObjectStore.TraceProvider.Id);
private BinderReferenceHolder _refHolder;
diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/DependencyObject/DependencyObjectGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/DependencyObject/DependencyObjectGenerator.cs
index 059614e4d766..9769dfb9e452 100644
--- a/src/SourceGenerators/Uno.UI.SourceGenerators/DependencyObject/DependencyObjectGenerator.cs
+++ b/src/SourceGenerators/Uno.UI.SourceGenerators/DependencyObject/DependencyObjectGenerator.cs
@@ -175,18 +175,15 @@ private void ProcessType(INamedTypeSymbol typeSymbol)
}
};
- var canBeTpProvider = !typeSymbol.Interfaces.Any(x => x.Name == "INotTemplatedParentProvider");
-
var implementations = new string?[]
{
"IDependencyObjectStoreProvider",
_isUnoSolution && !typeSymbol.IsSealed ? "IDependencyObjectInternal" : null,
- canBeTpProvider ? "ITemplatedParentProvider" : null,
"IWeakReferenceProvider",
}.Where(x => x is not null);
using (typeSymbol.AddToIndentedStringBuilder(builder, beforeClassHeaderAction, afterClassHeader: " : " + string.Join(", ", implementations)))
{
- GenerateDependencyObjectImplementation(typeSymbol, builder, hasDispatcherQueue: _dependencyObjectSymbol!.GetMembers("DispatcherQueue").Any(), canBeTpProvider);
+ GenerateDependencyObjectImplementation(typeSymbol, builder, hasDispatcherQueue: _dependencyObjectSymbol!.GetMembers("DispatcherQueue").Any());
GenerateIBinderImplementation(typeSymbol, builder);
}
@@ -768,7 +765,7 @@ public override bool Equals(object other)
}
}
- private void GenerateDependencyObjectImplementation(INamedTypeSymbol typeSymbol, IndentedStringBuilder builder, bool hasDispatcherQueue, bool implTpProvider)
+ private void GenerateDependencyObjectImplementation(INamedTypeSymbol typeSymbol, IndentedStringBuilder builder, bool hasDispatcherQueue)
{
builder.AppendLineIndented(@"private DependencyObjectStore __storeBackingField;");
builder.AppendLineIndented(@"public global::Windows.UI.Core.CoreDispatcher Dispatcher => global::Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;");
@@ -818,37 +815,6 @@ private void GenerateDependencyObjectImplementation(INamedTypeSymbol typeSymbol,
builder.AppendLineIndented("internal virtual void OnPropertyChanged2(global::Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs args) { }");
}
}
-
- if (implTpProvider)
- {
- var unoBrowsableOnly = _isUnoSolution ? null : "[EditorBrowsable(EditorBrowsableState.Never)]";
-
- builder.AppendLine();
- builder.AppendMultiLineIndented($$"""
- {{unoBrowsableOnly}}private ManagedWeakReference _templatedParentWeakRef;
- {{unoBrowsableOnly}}public ManagedWeakReference GetTemplatedParentWeakRef() => _templatedParentWeakRef;
-
- {{unoBrowsableOnly}}public DependencyObject GetTemplatedParent() => _templatedParentWeakRef?.Target as DependencyObject;
- {{unoBrowsableOnly}}public void SetTemplatedParent(DependencyObject parent)
- {
- //if (parent != null)
- //{
- // global::System.Diagnostics.Debug.Assert(parent
- // is global::Windows.UI.Xaml.Controls.Control
- // or global::Windows.UI.Xaml.Controls.ContentPresenter
- // or global::Windows.UI.Xaml.Controls.ItemsPresenter);
- // global::System.Diagnostics.Debug.Assert(GetTemplatedParent() == null);
- //}
-
- SetTemplatedParentImpl(parent);
- }
- {{unoBrowsableOnly}}{{(typeSymbol.IsSealed ? "private" : "private protected virtual")}} void SetTemplatedParentImpl(DependencyObject parent)
- {
- _templatedParentWeakRef = (parent as IWeakReferenceProvider)?.WeakReference;
- }
- """
- );
- }
}
}
}
diff --git a/src/Uno.UI.Maps/MapPresenter.cs b/src/Uno.UI.Maps/MapPresenter.cs
index 9834068782a9..b3bd76863c74 100644
--- a/src/Uno.UI.Maps/MapPresenter.cs
+++ b/src/Uno.UI.Maps/MapPresenter.cs
@@ -25,7 +25,7 @@ private void UpdateOwnerSubscriptions()
{
_ownerSubscription.Disposable = null;
- _owner = GetTemplatedParent() as MapControl;
+ _owner = this.GetTemplatedParent() as MapControl;
if (_owner != null)
{
diff --git a/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml b/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml
deleted file mode 100644
index bfe83efffdbf..000000000000
--- a/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
diff --git a/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml.cs b/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml.cs
deleted file mode 100644
index 4c515ab34c65..000000000000
--- a/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-using System;
-using System.Diagnostics.CodeAnalysis;
-using Microsoft.UI.Xaml;
-using Microsoft.UI.Xaml.Controls;
-#if HAS_UNO
-using Uno.UI.DataBinding;
-#endif
-
-namespace Uno.UI.RuntimeTests.Tests.TemplatedParent.Setup;
-
-public sealed partial class BehaviorSetup : Page
-{
- public BehaviorSetup()
- {
- this.InitializeComponent();
- }
-}
-
-public sealed class Interaction
-{
- #region DependencyProperty: Behaviors
-
- public static DependencyProperty BehaviorsProperty { get; } = DependencyProperty.RegisterAttached(
- "Behaviors",
- typeof(BehaviorCollection),
- typeof(Interaction),
- new PropertyMetadata(null, OnBehaviorsChanged));
-
- public static BehaviorCollection GetBehaviors(DependencyObject obj) => GetBehaviorsOverride(obj);
- public static void SetBehaviors(DependencyObject obj, BehaviorCollection value) => obj.SetValue(BehaviorsProperty, value);
-
- #endregion
-
- private static BehaviorCollection GetBehaviorsOverride(DependencyObject obj)
- {
- var value = (BehaviorCollection)obj.GetValue(BehaviorsProperty);
- if (value is null)
- {
- obj.SetValue(BehaviorsProperty, value = new BehaviorCollection());
- }
-
- return value;
- }
-
- private static void OnBehaviorsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
- {
- if (e.NewValue is BehaviorCollection collection)
- {
- collection.AssociatedObject = sender;
- }
- }
-}
-public sealed class BehaviorCollection : DependencyObjectCollection
-{
- public DependencyObject AssociatedObject { get; set; }
-}
-
-public interface IBehavior { }
-
-public partial class LegacyDOBehavior : DependencyObject, IBehavior
-#if HAS_UNO
- , INotTemplatedParentProvider
-#endif
-{
- #region DependencyProperty: TestValue
-
- public static DependencyProperty TestValueProperty { get; } = DependencyProperty.Register(
- nameof(TestValue),
- typeof(object),
- typeof(LegacyDOBehavior),
- new PropertyMetadata(default(object), OnTestValueChanged));
-
- public object TestValue
- {
- get => (object)GetValue(TestValueProperty);
- set => SetValue(TestValueProperty, value);
- }
-
- #endregion
-
- private static void OnTestValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
- {
- }
-}
-public partial class NonLegacyDOBehavior : DependencyObject, IBehavior
-{
- #region DependencyProperty: TestValue
-
- public static DependencyProperty TestValueProperty { get; } = DependencyProperty.Register(
- nameof(TestValue),
- typeof(object),
- typeof(NonLegacyDOBehavior),
- new PropertyMetadata(default(object), OnTestValueChanged));
-
- public object TestValue
- {
- get => (object)GetValue(TestValueProperty);
- set => SetValue(TestValueProperty, value);
- }
-
- #endregion
-
- private static void OnTestValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
- {
- }
-}
diff --git a/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/TemplatedParentTests.cs b/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/TemplatedParentTests.cs
index 2d2b4b02aeaa..a82b2487509d 100644
--- a/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/TemplatedParentTests.cs
+++ b/src/Uno.UI.RuntimeTests/Tests/TemplatedParent/TemplatedParentTests.cs
@@ -289,27 +289,6 @@ public async Task VisualStateGroup_TP_Inheritance()
""";
VerifyTree(expectations, setup, checkVSG: true);
}
-
-#if HAS_UNO
- [TestMethod]
- public async Task LegacyDO_StillSupports_TP_Injection()
- {
- var setup = new BehaviorSetup();
- await UITestHelper.Load(setup, x => x.IsLoaded);
-
- var button = setup.Content as Button ?? throw new Exception("button not found");
- var grid = button.GetTemplateRoot() ?? throw new Exception("template root not found");
- var collection = Interaction.GetBehaviors(grid) ?? throw new Exception("behavior collection not found");
-
- var sut0 = collection.ElementAtOrDefault(0) as LegacyDOBehavior;
-
- // Verify that "legacy DepObj"(DO from library built before templated-parent rework)
- // 1. is simulated correctly via the "INotTemplatedParentProvider" blocker
- Assert.IsNotInstanceOfType(sut0, "sut0 shouldnt impl ITemplatedParentProvider");
- // 2. still supports tp-injection.
- Assert.AreEqual(button.Tag, sut0.TestValue, "sut0.TestValue template-binding failed");
- }
-#endif
}
public partial class TemplatedParentTests // helper methods
{
diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_VisualStateManager.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_VisualStateManager.cs
index 3a51ccce3318..4c6567b05172 100644
--- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_VisualStateManager.cs
+++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_VisualStateManager.cs
@@ -1,7 +1,15 @@
+using System;
+using System.Linq;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media;
+using Microsoft.UI.Xaml.Shapes;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using MUXControlsTestApp.Utilities;
+using Uno.Extensions;
+using Uno.UI.Extensions;
using Uno.UI.RuntimeTests.Helpers;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml;
@@ -30,4 +38,45 @@ public async Task When_Transition_Modifies_SubProperty_Of_Property_Set_By_Previo
await Task.Delay(1000);
Assert.AreEqual(Microsoft.UI.Colors.Red, ((SolidColorBrush)border.Background).Color);
}
+
+ [TestMethod]
+ public async Task SelectorItem_SelectedState()
+ {
+ var items = Enumerable.Range(0, 3).ToArray();
+ var setup = new GridView
+ {
+ ItemsSource = items,
+ SelectedItem = items.Last(),
+ };
+ await UITestHelper.Load(setup);
+
+ var container2 = setup.ContainerFromIndex(2) as GridViewItem ?? throw new Exception("Failed to retrieve container at index 2");
+
+ // check if the visual-state is set
+ var states = VisualStateHelper.GetCurrentVisualStateName(container2).ToArray();
+ Assert.IsTrue(states.Contains("Selected"), $"container2 is not in 'Selected' state: states={states.JoinBy(",")}");
+ }
+
+ [TestMethod]
+ public Task SelectorItem_MultiSelectState_GV() => SelectorItem_MultiSelectState_Impl();
+
+ [TestMethod]
+ public Task SelectorItem_MultiSelectState_LV() => SelectorItem_MultiSelectState_Impl();
+
+ public async Task SelectorItem_MultiSelectState_Impl() where T : ListViewBase, new()
+ {
+ var items = Enumerable.Range(0, 3).ToArray();
+ var setup = new T
+ {
+ ItemsSource = items,
+ SelectionMode = ListViewSelectionMode.Multiple,
+ };
+ await UITestHelper.Load(setup);
+
+ var container2 = setup.ContainerFromIndex(2) as SelectorItem ?? throw new Exception("Failed to retrieve container at index 2");
+
+ // check if the visual-state is set
+ var states = VisualStateHelper.GetCurrentVisualStateName(container2).ToArray();
+ Assert.IsTrue(states.Contains("MultiSelectEnabled"), $"container2 is not in 'MultiSelectEnabled' state: states={states.JoinBy(",")}");
+ }
}
diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs
index aad9f8473787..32fc7b0a5aed 100644
--- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs
+++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs
@@ -12,6 +12,7 @@
using static Private.Infrastructure.TestServices;
using Uno.UI.Extensions;
using Microsoft.UI.Xaml.Controls.Primitives;
+using Uno.UI.RuntimeTests.Helpers;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
{
@@ -126,6 +127,24 @@ public async Task Check_Changing_SelectedItem_Affects_SelectedIndex()
SUT.SelectedItem.Should().Be(pivotItem2);
}
+ [TestMethod]
+ [RunsOnUIThread]
+ public async Task Pivot_Single_ItemContent_Visible()
+ {
+ var items = Enumerable.Range(0, 3).ToArray();
+ var setup = new Pivot
+ {
+ ItemsSource = items,
+ SelectedItem = items.Last(),
+ };
+ await UITestHelper.Load(setup);
+
+ var containers = items.Select((x, i) => setup.ContainerFromIndex(i)).OfType().ToArray();
+
+ Assert.AreEqual(3, containers.Length, "Should have 3 containers");
+ Assert.AreEqual(1, containers.Count(x => x.Visibility == Visibility.Visible), "Only one PivotItem should be visible");
+ }
+
private class MyContext
{
public MyContext()
diff --git a/src/Uno.UI/AssemblyInfo.cs b/src/Uno.UI/AssemblyInfo.cs
index 0c1a21251bd8..0197304d873a 100644
--- a/src/Uno.UI/AssemblyInfo.cs
+++ b/src/Uno.UI/AssemblyInfo.cs
@@ -16,6 +16,7 @@
[assembly: InternalsVisibleTo("Uno.UI.Svg")]
[assembly: InternalsVisibleTo("Uno.UI.Svg.Skia")]
[assembly: InternalsVisibleTo("Uno.UI.XamlHost")]
+[assembly: InternalsVisibleTo("Uno.UI.Maps")]
[assembly: InternalsVisibleTo("SamplesApp")]
[assembly: InternalsVisibleTo("SamplesApp.Droid")]
[assembly: InternalsVisibleTo("SamplesApp.macOS")]
diff --git a/src/Uno.UI/Controls/NativeFramePresenter.iOS.cs b/src/Uno.UI/Controls/NativeFramePresenter.iOS.cs
index acf1b430333d..77ef99731c6f 100644
--- a/src/Uno.UI/Controls/NativeFramePresenter.iOS.cs
+++ b/src/Uno.UI/Controls/NativeFramePresenter.iOS.cs
@@ -16,6 +16,7 @@
using System.Collections.Specialized;
using System.Threading.Tasks;
using ObjCRuntime;
+using Uno.UI.Extensions;
namespace Uno.UI.Controls
{
@@ -88,19 +89,19 @@ public NativeFramePresenter()
NavigationController.NavigationBarHidden = true;
}
+ private protected override void OnLoaded()
+ {
+ base.OnLoaded();
+
+ InitializeController(this.GetTemplatedParent() as Frame);
+ }
+
protected override Size MeasureOverride(Size availableSize)
=> MeasureFirstChild(availableSize);
protected override Size ArrangeOverride(Size finalSize)
=> ArrangeFirstChild(finalSize);
- private protected override void SetTemplatedParentImpl(DependencyObject parent)
- {
- base.SetTemplatedParentImpl(parent);
-
- InitializeController(parent as Frame);
- }
-
///
/// Exposes the underlying instance used to display this frame presenter.
///
diff --git a/src/Uno.UI/DataBinding/BindingExpression.cs b/src/Uno.UI/DataBinding/BindingExpression.cs
index ec18e118ad06..6a57eb0b2eb7 100644
--- a/src/Uno.UI/DataBinding/BindingExpression.cs
+++ b/src/Uno.UI/DataBinding/BindingExpression.cs
@@ -54,13 +54,7 @@ public object DataContext
{
if (ParentBinding.IsTemplateBinding)
{
- return _view?.Target switch
- {
- ITemplatedParentProvider tpProvider => tpProvider.GetTemplatedParent(),
- IDependencyObjectStoreProvider dosProvider => dosProvider.Store.GetTemplatedParent2(),
-
- _ => null,
- };
+ return (_view?.Target as IDependencyObjectStoreProvider)?.Store.GetTemplatedParent2();
}
if (_isElementNameSource || ExplicitSource != null)
{
@@ -157,13 +151,7 @@ Binding binding
private ManagedWeakReference GetWeakTemplatedParent()
{
- return _view?.Target switch
- {
- ITemplatedParentProvider tpProvider => tpProvider.GetTemplatedParentWeakRef(),
- IDependencyObjectStoreProvider dosProvider => dosProvider.Store.GetTemplatedParentWeakRef(),
-
- _ => null,
- };
+ return (_view?.Target as IDependencyObjectStoreProvider)?.Store.GetTemplatedParentWeakRef();
}
private ManagedWeakReference GetWeakDataContext()
diff --git a/src/Uno.UI/DataBinding/ITemplatedParentProvider.cs b/src/Uno.UI/DataBinding/ITemplatedParentProvider.cs
deleted file mode 100644
index c307f4f02ff3..000000000000
--- a/src/Uno.UI/DataBinding/ITemplatedParentProvider.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.UI.Xaml;
-
-namespace Uno.UI.DataBinding;
-
-[EditorBrowsable(EditorBrowsableState.Never)]
-public interface ITemplatedParentProvider
-{
- ManagedWeakReference GetTemplatedParentWeakRef();
-
- DependencyObject GetTemplatedParent();
-
- void SetTemplatedParent(DependencyObject parent);
-}
-
-[EditorBrowsable(EditorBrowsableState.Never)]
-///
-/// Marker interface used to block DependencyObjectGenerator
-/// from injecting and its implementations.
-///
-public interface INotTemplatedParentProvider
-{
-}
diff --git a/src/Uno.UI/NativeFramePresenter.Android.cs b/src/Uno.UI/NativeFramePresenter.Android.cs
index 0729cfbfda17..c031e4abb882 100644
--- a/src/Uno.UI/NativeFramePresenter.Android.cs
+++ b/src/Uno.UI/NativeFramePresenter.Android.cs
@@ -38,11 +38,11 @@ public NativeFramePresenter()
_pageStack = this;
}
- private protected override void SetTemplatedParentImpl(DependencyObject parent)
+ private protected override void OnLoaded()
{
- base.SetTemplatedParentImpl(parent);
+ base.OnLoaded();
- Initialize(parent as Frame);
+ Initialize(this.GetTemplatedParent() as Frame);
}
private void Initialize(Frame frame)
diff --git a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/NativeScrollContentPresenter.iOS.cs b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/NativeScrollContentPresenter.iOS.cs
index 8b42f95b8eaf..89a8be2e9f67 100644
--- a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/NativeScrollContentPresenter.iOS.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/NativeScrollContentPresenter.iOS.cs
@@ -107,7 +107,7 @@ private void InvokeOnScroll()
scroller.Presenter.OnNativeScroll(clampedOffset.X, clampedOffset.Y, isIntermediate: _isInAnimatedScroll);
}
- private ScrollViewer GetParentScrollViewer() => _scrollViewer.TryGetTarget(out var s) ? s : GetTemplatedParent() as ScrollViewer;
+ private ScrollViewer GetParentScrollViewer() => _scrollViewer.TryGetTarget(out var s) ? s : this.GetTemplatedParent() as ScrollViewer;
// Called when user starts dragging
private void OnDraggingStarted(object sender, EventArgs e)
diff --git a/src/Uno.UI/UI/Xaml/DependencyObjectExtensions.cs b/src/Uno.UI/UI/Xaml/DependencyObjectExtensions.cs
index 0036e8a9d464..c3d0de4a08be 100644
--- a/src/Uno.UI/UI/Xaml/DependencyObjectExtensions.cs
+++ b/src/Uno.UI/UI/Xaml/DependencyObjectExtensions.cs
@@ -448,5 +448,15 @@ internal static void RegisterPropertyChangedCallbackStrong(this IDependencyObjec
// allows for some customization - e.g. glyphs should not respect this.
internal static bool IsRightToLeft(this DependencyObject dependencyObject) =>
dependencyObject is FrameworkElement fw && fw.FlowDirection == FlowDirection.RightToLeft;
+
+ internal static DependencyObject GetTemplatedParent(this DependencyObject @do)
+ {
+ return (@do as IDependencyObjectStoreProvider)?.Store.GetTemplatedParent2();
+ }
+
+ internal static void SetTemplatedParent(this DependencyObject @do, DependencyObject tp)
+ {
+ (@do as IDependencyObjectStoreProvider)?.Store.SetTemplatedParent2(tp);
+ }
}
}
diff --git a/src/Uno.UI/UI/Xaml/FrameworkElement.cs b/src/Uno.UI/UI/Xaml/FrameworkElement.cs
index 1cceaf162fe0..cd0f17591dde 100644
--- a/src/Uno.UI/UI/Xaml/FrameworkElement.cs
+++ b/src/Uno.UI/UI/Xaml/FrameworkElement.cs
@@ -1085,5 +1085,14 @@ private protected virtual bool HasTemplateChild()
return null;
}
+
+ internal DependencyObject GetTemplatedParent()
+ {
+ return (this as IDependencyObjectStoreProvider)?.Store.GetTemplatedParent2();
+ }
+ internal void SetTemplatedParent(DependencyObject tp)
+ {
+ (this as IDependencyObjectStoreProvider)?.Store.SetTemplatedParent2(tp);
+ }
}
}
diff --git a/src/Uno.UI/UI/Xaml/TemplatedParentScope.cs b/src/Uno.UI/UI/Xaml/TemplatedParentScope.cs
index 2d85062f360c..abfc2351690d 100644
--- a/src/Uno.UI/UI/Xaml/TemplatedParentScope.cs
+++ b/src/Uno.UI/UI/Xaml/TemplatedParentScope.cs
@@ -15,8 +15,11 @@ internal static class TemplatedParentScope
/// Set the templated-parent for the dependency-object based on the currently materializing template.
///
/// Should be true, if not called from ctor.
+ ///
internal static void UpdateTemplatedParentIfNeeded(DependencyObject? @do, bool reapplyTemplateBindings = false, DependencyObjectStore? store = null)
{
+ // note: `store` instance is used within DOStore.ctor to avoid stack overflow.
+
if (@do is null) return;
if (GetCurrentTemplate() is { IsLegacyTemplate: true, TemplatedParent: { } tp })
{
@@ -26,22 +29,18 @@ internal static void UpdateTemplatedParentIfNeeded(DependencyObject? @do, bool r
internal static void UpdateTemplatedParent(DependencyObject? @do, DependencyObject tp, bool reapplyTemplateBindings = true, DependencyObjectStore? store = null)
{
- if (@do is ITemplatedParentProvider tpProvider)
+ if (@do is IDependencyObjectStoreProvider provider)
{
- tpProvider.SetTemplatedParent(tp);
+ (store ?? provider.Store).SetTemplatedParent2(tp);
// note: This can be safely removed, once moving away from legacy impl.
// In the new impl, the templated-parent would be immediately available
// before any binding is applied, so there is no need to force update.
- if (reapplyTemplateBindings && @do is IDependencyObjectStoreProvider dosProvider)
+ if (reapplyTemplateBindings)
{
- (store ?? dosProvider.Store).ApplyTemplateBindings();
+ (store ?? provider.Store).ApplyTemplateBindings();
}
}
- else if (@do is IDependencyObjectStoreProvider dosProvider)
- {
- (store ?? dosProvider.Store).SetTemplatedParent2(tp);
- }
}
internal static MaterializingTemplateInfo? GetCurrentTemplate()
diff --git a/src/Uno.UI/UI/Xaml/VisualState.cs b/src/Uno.UI/UI/Xaml/VisualState.cs
index 6f41073e312a..5dafa8649b72 100644
--- a/src/Uno.UI/UI/Xaml/VisualState.cs
+++ b/src/Uno.UI/UI/Xaml/VisualState.cs
@@ -165,7 +165,7 @@ private void EnsureMaterialized()
LazyBuilder = null;
try
{
- TemplatedParentScope.PushScope(GetTemplatedParent(), FromLegacyTemplate == true);
+ TemplatedParentScope.PushScope(this.GetTemplatedParent(), FromLegacyTemplate == true);
builder.Invoke();
}
finally
diff --git a/src/Uno.UI/UI/Xaml/VisualTransition.cs b/src/Uno.UI/UI/Xaml/VisualTransition.cs
index 2b4c5788ddb3..8d66b875799c 100644
--- a/src/Uno.UI/UI/Xaml/VisualTransition.cs
+++ b/src/Uno.UI/UI/Xaml/VisualTransition.cs
@@ -51,7 +51,7 @@ private void EnsureMaterialized()
LazyBuilder = null;
try
{
- TemplatedParentScope.PushScope(GetTemplatedParent(), FromLegacyTemplate == true);
+ TemplatedParentScope.PushScope(this.GetTemplatedParent(), FromLegacyTemplate == true);
builder.Invoke();
}
finally