diff --git a/src/SourceGenerators/System.Xaml.Tests/Test/System.Xaml/XamlXmlReaderTest.cs b/src/SourceGenerators/System.Xaml.Tests/Test/System.Xaml/XamlXmlReaderTest.cs index f24ae58f0a09..e2a7db8e47ae 100644 --- a/src/SourceGenerators/System.Xaml.Tests/Test/System.Xaml/XamlXmlReaderTest.cs +++ b/src/SourceGenerators/System.Xaml.Tests/Test/System.Xaml/XamlXmlReaderTest.cs @@ -360,6 +360,7 @@ public void Read_GenericSimple() [Test] public void Read_GenericWithProperty() { + const string not_win = "{http://uno.ui/not_win}"; var sequence = new SequenceItem[] { new SequenceItem { NodeType = XamlNodeType.NamespaceDeclaration, }, new SequenceItem { NodeType = XamlNodeType.NamespaceDeclaration, }, @@ -382,16 +383,18 @@ public void Read_GenericWithProperty() new SequenceItem { NodeType = XamlNodeType.EndMember, }, new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml}_UnknownContent", }, - new SequenceItem { NodeType = XamlNodeType.StartObject, TypeName = "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Style"}, + new SequenceItem { NodeType = XamlNodeType.StartObject, TypeName = $"{not_win}Style"}, new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml}Key", }, new SequenceItem { NodeType = XamlNodeType.Value, Value = "DefaultComboBoxItemStyle", }, new SequenceItem { NodeType = XamlNodeType.EndMember, }, - new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Style.OtherProperty", }, + new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = $"{not_win}Style.OtherProperty", }, new SequenceItem { NodeType = XamlNodeType.Value, Value = "test", }, new SequenceItem { NodeType = XamlNodeType.EndMember, }, +#if false // XamlXmlReader fails to read any xmlns'd node/attribute with invalid uri (such as a guid or 'using:System.Somewhere') new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Style.TargetType", }, new SequenceItem { NodeType = XamlNodeType.Value, Value = "SelectorItem", }, new SequenceItem { NodeType = XamlNodeType.EndMember, }, +#endif new SequenceItem { NodeType = XamlNodeType.EndObject, }, new SequenceItem { NodeType = XamlNodeType.EndMember, }, new SequenceItem { NodeType = XamlNodeType.EndObject, }, @@ -2507,9 +2510,30 @@ public void Bug680385 () } #endregion + private string GetXml(string fileName) + { + var directory = Path.GetDirectoryName(new Uri(GetType().Assembly.CodeBase).LocalPath); + var path = Path.Combine(directory, "Test/XmlFiles", fileName); + + return File.ReadAllText(path).Replace("System.Xaml_test_net_4_0", "Uno.Xaml.Tests"); + } + + private IEnumerable<(XamlNodeType, string, string, object, string)> ReadAllTokens(string fileName) + { + var r = GetReader(fileName); + int i = 0; + while (r.Read()) + { + yield return (r.NodeType, r.Member?.ToString(), r.Member?.Name, r.Value, r.Type?.ToString()); + } + } + private void ReadSequence(string fileName, IEnumerable sequence) { - //ReadTest(fileName); +#if DEBUG && false + var xml = GetXml(fileName); + var tokens = ReadAllTokens(fileName).ToArray(); +#endif var r = GetReader(fileName); 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 3fa7d8a122fe..109aee902a61 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs @@ -97,6 +97,7 @@ internal partial class Inner : DependencyObject using System.Linq; using System.Collections.Generic; using System.Collections; + using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using Uno.Disposables; using System.Runtime.CompilerServices; @@ -112,7 +113,7 @@ internal partial class Inner : DependencyObject partial class OuterClass { [global::Microsoft.UI.Xaml.Data.Bindable] - partial class Inner : IDependencyObjectStoreProvider, IWeakReferenceProvider + partial class Inner : IDependencyObjectStoreProvider, ITemplatedParentProvider, IWeakReferenceProvider { private DependencyObjectStore __storeBackingField; public global::Windows.UI.Core.CoreDispatcher Dispatcher => global::Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher; @@ -123,7 +124,7 @@ private DependencyObjectStore __Store { if(__storeBackingField == null) { - __storeBackingField = new DependencyObjectStore(this, DataContextProperty, TemplatedParentProperty); + __storeBackingField = new DependencyObjectStore(this, DataContextProperty); __InitializeBinder(); } return __storeBackingField; @@ -138,6 +139,28 @@ 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; @@ -220,36 +243,6 @@ internal protected virtual void OnDataContextChanged(DependencyPropertyChangedEv #endregion - #region TemplatedParent DependencyProperty - - public DependencyObject TemplatedParent - { - get => (DependencyObject)GetValue(TemplatedParentProperty); - set => SetValue(TemplatedParentProperty, value); - } - - // Using a DependencyProperty as the backing store for TemplatedParent. This enables animation, styling, binding, etc... - public static DependencyProperty TemplatedParentProperty { get ; } = - DependencyProperty.Register( - name: nameof(TemplatedParent), - propertyType: typeof(DependencyObject), - ownerType: typeof(Inner), - typeMetadata: new FrameworkPropertyMetadata( - defaultValue: null, - options: FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.WeakStorage, - propertyChangedCallback: (s, e) => ((Inner)s).OnTemplatedParentChanged(e) - ) - ); - - - internal protected virtual void OnTemplatedParentChanged(DependencyPropertyChangedEventArgs e) - { - __Store.SetTemplatedParent(e.NewValue as FrameworkElement); - OnTemplatedParentChangedPartial(e); - } - - #endregion - public void SetBinding(object target, string dependencyProperty, global::Microsoft.UI.Xaml.Data.BindingBase binding) { __Store.SetBinding(target, dependencyProperty, binding); @@ -275,8 +268,6 @@ public void SetBindingValue(object value, [CallerMemberName] string propertyName partial void OnDataContextChangedPartial(DependencyPropertyChangedEventArgs e); - partial void OnTemplatedParentChangedPartial(DependencyPropertyChangedEventArgs e); - public global::Microsoft.UI.Xaml.Data.BindingExpression GetBindingExpression(DependencyProperty dependencyProperty) => __Store.GetBindingExpression(dependencyProperty); diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs index 54c7ca88673d..b7a37398c42f 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs @@ -111,7 +111,7 @@ private void InitializeComponent() "MyItemTemplate" ] = new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_1 => - new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1 , __owner => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner) + new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner, __settings) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner, __settings) ) .GenericApply(__that, __nameScope, ((c6, __that, __nameScope) => { global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c6, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L13:6"); @@ -125,7 +125,7 @@ private void InitializeComponent() { IsParsing = true, Name = "TheListView", - HeaderTemplate = new global::Microsoft.UI.Xaml.DataTemplate(this , __owner => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1>()).Build(__owner) + HeaderTemplate = new global::Microsoft.UI.Xaml.DataTemplate(this, (__owner, __settings) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1>()).Build(__owner, __settings) ) .GenericApply(__that, __nameScope, ((c7, __that, __nameScope) => { global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c7, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L42:8"); @@ -312,7 +312,7 @@ private void InitializeComponent() } internal interface I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 { - _View Build(object owner); + _View Build(object owner, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings); } [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -323,7 +323,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 : [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); - public _View Build(object __ResourceOwner_1) + public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings) { _View __rootInstance = null; var __that = this; @@ -341,6 +341,8 @@ public _View Build(object __ResourceOwner_1) } .GenericApply(__that, __nameScope, ((c17, __that, __nameScope) => { + c17.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c17); c17.SetBinding( global::Microsoft.UI.Xaml.Controls.TextBlock.TextProperty, new Microsoft.UI.Xaml.Data.Binding() @@ -361,6 +363,8 @@ public _View Build(object __ResourceOwner_1) } .GenericApply(__that, __nameScope, ((c18, __that, __nameScope) => { + c18.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c18); /* _isTopLevelDictionary:False */ __that._component_0 = c18; global::Uno.UI.ResourceResolverSingleton.Instance.ApplyResource(c18, global::Microsoft.UI.Xaml.Controls.Button.StyleProperty, "MyCustomButtonStyle", isThemeResourceExtension: false, isHotReloadSupported: true, context: global::MyProject.GlobalStaticResources.__ParseContext_); @@ -373,6 +377,8 @@ public _View Build(object __ResourceOwner_1) } .GenericApply(__that, __nameScope, ((c19, __that, __nameScope) => { + c19.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c19); global::Uno.UI.FrameworkElementHelper.SetBaseUri(c19, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d, "file:///C:/Project/0/MainPage.xaml", 14, 8); c19.CreationComplete(); } @@ -413,7 +419,7 @@ public _View Build(object __ResourceOwner_1) } internal interface I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1 { - _View Build(object owner); + _View Build(object owner, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings); } [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -424,7 +430,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1 : [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); - public _View Build(object __ResourceOwner_1) + public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings) { _View __rootInstance = null; var __that = this; @@ -437,6 +443,8 @@ public _View Build(object __ResourceOwner_1) } .GenericApply(__that, __nameScope, ((c20, __that, __nameScope) => { + c20.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c20); global::Uno.UI.FrameworkElementHelper.SetBaseUri(c20, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d, "file:///C:/Project/0/MainPage.xaml", 43, 10); c20.CreationComplete(); } diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs index 580c82975ec5..e43107ce88e3 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs @@ -111,7 +111,7 @@ private void InitializeComponent() "MyItemTemplate" ] = new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_1 => - new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1 , __owner => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner) + new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner, __settings) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner, __settings) ) .GenericApply(__that, __nameScope, ((c6, __that, __nameScope) => { global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c6, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L13:6"); @@ -167,7 +167,7 @@ private void InitializeComponent() partial void OnInitializeCompleted(); internal interface I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 { - _View Build(object owner); + _View Build(object owner, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings); } [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] @@ -178,7 +178,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 : [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); - public _View Build(object __ResourceOwner_1) + public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings) { _View __rootInstance = null; var __that = this; @@ -196,6 +196,8 @@ public _View Build(object __ResourceOwner_1) } .GenericApply(__that, __nameScope, ((c10, __that, __nameScope) => { + c10.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c10); c10.SetBinding( global::Microsoft.UI.Xaml.Controls.TextBlock.TextProperty, new Microsoft.UI.Xaml.Data.Binding() @@ -216,6 +218,8 @@ public _View Build(object __ResourceOwner_1) } .GenericApply(__that, __nameScope, ((c11, __that, __nameScope) => { + c11.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c11); /* _isTopLevelDictionary:False */ __that._component_0 = c11; global::Uno.UI.ResourceResolverSingleton.Instance.ApplyResource(c11, global::Microsoft.UI.Xaml.Controls.Button.StyleProperty, "MyCustomButtonStyle", isThemeResourceExtension: false, isHotReloadSupported: true, context: global::MyProject.GlobalStaticResources.__ParseContext_); @@ -228,6 +232,8 @@ public _View Build(object __ResourceOwner_1) } .GenericApply(__that, __nameScope, ((c12, __that, __nameScope) => { + c12.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c12); global::Uno.UI.FrameworkElementHelper.SetBaseUri(c12, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d, "file:///C:/Project/0/MainPage.xaml", 14, 8); c12.CreationComplete(); } diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/TDBMIDTIRD/XamlCodeGenerator_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/TDBMIDTIRD/XamlCodeGenerator_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57.cs index 807ba550ca6a..da599e18990e 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/TDBMIDTIRD/XamlCodeGenerator_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/TDBMIDTIRD/XamlCodeGenerator_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57.cs @@ -46,7 +46,7 @@ public void InitializeComponent() "myTemplate" ] = new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_1 => - new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1 , __owner => new _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_TestReproMyResourceDictionarySC0().Build(__owner) + new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner, __settings) => new _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_TestReproMyResourceDictionarySC0().Build(__owner, __settings) ) ) ; } @@ -59,7 +59,7 @@ private class _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_TestReproMy [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] private const string __baseUri_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57 = "ms-appx:///TestProject/"; global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); - public _View Build(object __ResourceOwner_1) + public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings) { _View __rootInstance = null; var __that = this; @@ -72,6 +72,8 @@ public _View Build(object __ResourceOwner_1) } .MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_XamlApply((MyResourceDictionary_92716e07ff456818f6d4125e055d4d57XamlApplyExtensions.XamlApplyHandler0)(c0 => { + c0.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c0); /* _isTopLevelDictionary:True */ __that._component_0 = c0; __nameScope.RegisterName("tb", c0); @@ -178,7 +180,7 @@ public ResourceDictionarySingleton__MyResourceDictionary_92716e07ff456818f6d4125 // Method for resource myTemplate private object Get_1(object __ResourceOwner_1) => - new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1 , __owner => new __Resources._MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionaryRDSC1().Build(__owner) + new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner, __settings) => new __Resources._MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionaryRDSC1().Build(__owner, __settings) ) ; private global::Microsoft.UI.Xaml.ResourceDictionary _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_ResourceDictionary; @@ -197,7 +199,7 @@ private object Get_1(object __ResourceOwner_1) => "myTemplate" ] = new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_1 => - new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1 , __owner => new __Resources._MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionaryRDSC2().Build(__owner) + new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner, __settings) => new __Resources._MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionaryRDSC2().Build(__owner, __settings) ) ) , } @@ -225,7 +227,7 @@ class _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionar [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] private const string __baseUri_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57 = "ms-appx:///TestProject/"; global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); - public _View Build(object __ResourceOwner_1) + public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings) { _View __rootInstance = null; var __that = this; @@ -238,6 +240,8 @@ public _View Build(object __ResourceOwner_1) } .MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_XamlApply((MyResourceDictionary_92716e07ff456818f6d4125e055d4d57XamlApplyExtensions.XamlApplyHandler0)(c1 => { + c1.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c1); /* _isTopLevelDictionary:True */ __that._component_0 = c1; __nameScope.RegisterName("tb", c1); @@ -314,7 +318,7 @@ class _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionar [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] private const string __baseUri_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57 = "ms-appx:///TestProject/"; global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); - public _View Build(object __ResourceOwner_1) + public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings) { _View __rootInstance = null; var __that = this; @@ -327,6 +331,8 @@ public _View Build(object __ResourceOwner_1) } .MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_XamlApply((MyResourceDictionary_92716e07ff456818f6d4125e055d4d57XamlApplyExtensions.XamlApplyHandler0)(c2 => { + c2.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c2); /* _isTopLevelDictionary:True */ __that._component_0 = c2; __nameScope.RegisterName("tb", c2); diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBENIT/XamlCodeGenerator_Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBENIT/XamlCodeGenerator_Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca.cs index 2bfcbd8de737..d653ab68ff01 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBENIT/XamlCodeGenerator_Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBENIT/XamlCodeGenerator_Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca.cs @@ -59,7 +59,7 @@ private void InitializeComponent() IsParsing = true, Name = "topLevel", Tag = @"42", - ContentTemplate = new global::Microsoft.UI.Xaml.DataTemplate(this , __owner => new _Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca_UnoUITestsWindows_UI_Xaml_DataBindingTestsControlsBinding_ElementName_In_TemplateSC0().Build(__owner) + ContentTemplate = new global::Microsoft.UI.Xaml.DataTemplate(this, (__owner, __settings) => new _Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca_UnoUITestsWindows_UI_Xaml_DataBindingTestsControlsBinding_ElementName_In_TemplateSC0().Build(__owner, __settings) ) , // Source 0\Binding_ElementName_In_Template.xaml (Line 11:4) } @@ -123,7 +123,7 @@ private class _Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca_ [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] private const string __baseUri_Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca = "ms-appx:///TestProject/"; global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); - public _View Build(object __ResourceOwner_1) + public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings) { _View __rootInstance = null; var __that = this; @@ -136,6 +136,8 @@ public _View Build(object __ResourceOwner_1) } .Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca_XamlApply((Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237ecaXamlApplyExtensions.XamlApplyHandler2)(c4 => { + c4.SetTemplatedParent(__settings?.TemplatedParent); + __settings?.TemplateMemberCreatedCallback?.Invoke(c4); /* _isTopLevelDictionary:False */ __that._component_0 = c4; __nameScope.RegisterName("innerTextBlock", c4); diff --git a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyObject.cs b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyObject.cs index fb401436fd4d..20cccc2f0184 100644 --- a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyObject.cs +++ b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyObject.cs @@ -73,7 +73,7 @@ public void When_Set_Parent() var child = new MyObject(12); var parent = new MyObject(144); - var store = new DependencyObjectStore(child, MyObject.DataContextProperty, MyObject.TemplatedParentProperty); + var store = new DependencyObjectStore(child, MyObject.DataContextProperty); store.Parent = parent; Assert.AreEqual(parent, store.Parent); @@ -87,7 +87,7 @@ public void When_Set_Parent_As_WeakReferenceProvider() var child = new MyObject(12); var parent = new MyProvider(); - var store = new DependencyObjectStore(child, MyObject.DataContextProperty, MyObject.TemplatedParentProperty); + var store = new DependencyObjectStore(child, MyObject.DataContextProperty); store.Parent = parent; Assert.AreEqual(parent, store.Parent); diff --git a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.DataContext.cs b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.DataContext.cs index a678828148fb..411395181de7 100644 --- a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.DataContext.cs +++ b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.DataContext.cs @@ -178,10 +178,8 @@ public void When_ValueInheritDataContext_And_IList() SUT.MyList = new List() { sub1 }; SUT.DataContext = 42; - SUT.TemplatedParent = templatedParent; Assert.AreEqual(42, sub1.DataContext); - Assert.AreEqual(templatedParent, sub1.TemplatedParent); } [TestMethod] @@ -194,10 +192,8 @@ public void When_ValueInheritDataContext_And_IList_Non_Enumerable() SUT.MyList = new NonEnumerableList() { sub1 }; SUT.DataContext = 42; - SUT.TemplatedParent = templatedParent; Assert.AreEqual(42, sub1.DataContext); - Assert.AreEqual(templatedParent, sub1.TemplatedParent); } [TestMethod] diff --git a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.ManualPropagation.cs b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.ManualPropagation.cs index bcfaf113c4e6..c5dc565863dc 100644 --- a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.ManualPropagation.cs +++ b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.ManualPropagation.cs @@ -78,84 +78,6 @@ public void When_PropertyReset_Then_Parent_removed() Assert.IsNull(inner.GetParent()); } - [TestMethod] - public void When_IsAutoPropertyInheritance_Disabled_TemplatedParent() - { - var SUT = new MyObject(); - var inner = new SubObject(); - - SUT.SubObject = inner; - - Assert.IsNull(inner.LastDataContextChangedValue); - - var parent = new Grid(); - SUT.TemplatedParent = parent; - - Assert.IsNull(inner.LastTemplatedParentChangedValue); - - Assert.AreEqual(parent, inner.TemplatedParent); - Assert.AreEqual(parent, inner.LastTemplatedParentChangedValue); - } - - [TestMethod] - public void When_IsAutoPropertyInheritance_Disabled_TemplatedParent_Binding() - { - var SUT = new MyObject(); - var inner = new SubObject(); - - SUT.SubObject = inner; - - Assert.IsNull(inner.LastDataContextChangedValue); - - var parent = new Grid() { Tag = 42 }; - SUT.TemplatedParent = parent; - - Assert.IsNull(inner.LastTemplatedParentChangedValue); - - inner.SetBinding( - SubObject.DataContextProperty, - new Binding() - { - Path = "Tag", - RelativeSource = RelativeSource.TemplatedParent - } - ); - - Assert.AreEqual(parent, inner.LastTemplatedParentChangedValue); - Assert.AreEqual(42, inner.DataContext); - } - - [TestMethod] - public void When_IsAutoPropertyInheritance_Multi_Disabled() - { - var SUT = new MyObject(); - var inner = new SubObject(); - var inner2 = new SubObject(); - - SUT.SubObject = inner; - inner.Inner = inner2; - - Assert.IsNull(inner.LastDataContextChangedValue); - - SUT.DataContext = 42; - - Assert.IsNull(inner.LastDataContextChangedValue); - Assert.AreEqual("", inner.MyStringProperty); - Assert.AreEqual("", inner2.MyStringProperty); - - inner2.SetBinding( - SubObject.MyStringPropertyProperty, - new Binding() - { - } - ); - - Assert.AreEqual(42, inner.LastDataContextChangedValue); - Assert.AreEqual(42, inner2.LastDataContextChangedValue); - Assert.AreEqual("", inner.MyStringProperty); - Assert.AreEqual("42", inner2.MyStringProperty); - } - [TestMethod] public void When_IsAutoPropertyInheritance_Multi_DataContext_Read_Top() { @@ -448,18 +370,11 @@ public SubObject() public object LastDataContextChangedValue { get; private set; } - public object LastTemplatedParentChangedValue { get; private set; } - partial void OnDataContextChangedPartial(DependencyPropertyChangedEventArgs e) { LastDataContextChangedValue = e.NewValue; } - partial void OnTemplatedParentChangedPartial(DependencyPropertyChangedEventArgs e) - { - LastTemplatedParentChangedValue = e.NewValue; - } - public int MyProperty { get { return (int)GetValue(MyPropertyProperty); } diff --git a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.Propagation.cs b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.Propagation.cs index 9dda77a6d337..61867acf16e8 100644 --- a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.Propagation.cs +++ b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.Propagation.cs @@ -384,12 +384,12 @@ void CreateSub() CreateSub(); - SUT.TemplatedParent = SUT; + //SUT.TemplatedParent = SUT; GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); - SUT.TemplatedParent = null; + //SUT.TemplatedParent = null; GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); diff --git a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.TemplatedParent.cs b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.TemplatedParent.cs index f9c395beb97f..1bb7c2614825 100644 --- a/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.TemplatedParent.cs +++ b/src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.TemplatedParent.cs @@ -23,81 +23,6 @@ namespace Uno.UI.Tests.BinderTests_TemplatedParent [TestClass] public partial class Given_DependencyProperty_TemplatedParent { - [TestMethod] - public void When_TemplatedParent_Loop() - { - var SUT = new MyObject() { Name = "root" }; - var level1 = new MyObject() { Name = "level1" }; - var level2 = new MyObject() { Name = "level2" }; - var level3 = new MyObject() { Name = "level3" }; - - level2.DataContext = null; - - SUT.InnerObject = level1; - level1.InnerObject = level2; - level2.InnerObject = level3; - level2.TemplatedParent = SUT; - - level2.DataContext = 43; - - Assert.IsNull(SUT.DataContext); - } - - [TestMethod] - public void When_ValueInheritsDataContext_Then_TemplatedParent_is_Propagated() - { - var SUT = new MyObject() { Name = "root" }; - var inner = new MyObject() { Name = "inner" }; - - SUT.InnerWithValueInheritsDataContext = inner; - - Assert.IsNull(inner.TemplatedParent); - - SUT.TemplatedParent = SUT; - - Assert.IsNotNull(inner.TemplatedParent); - - SUT.TemplatedParent = null; - - Assert.IsNull(inner.TemplatedParent); - } - - [TestMethod] - public void When_DataContextTemplateBinding() - { - var SUT = new MyObject() { Name = "root" }; - var inner = new MyObject() { Name = "inner" }; - - var tp = new MyObject() { Name = "tp", Tag = 42 }; - - SUT.InnerObject = inner; - - Assert.IsNull(inner.DataContext); - - inner.SetBinding( - MyObject.DataContextProperty, - new Binding - { - Path = new PropertyPath("Tag"), - RelativeSource = RelativeSource.TemplatedParent - } - ); - - SUT.TemplatedParent = tp; - - Assert.AreEqual(42, inner.DataContext); - - SUT.DataContext = 44; - - tp.Tag = 43; - Assert.AreEqual(43, inner.DataContext); - - var tp2 = new MyObject() { Name = "tp2", Tag = 44 }; - SUT.TemplatedParent = tp2; - - Assert.AreEqual(44, inner.DataContext); - } - } public partial class MyObject : FrameworkElement diff --git a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ComboBoxTests/Given_ComboBox.cs b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ComboBoxTests/Given_ComboBox.cs index a53a646201a6..9b507e2743d4 100644 --- a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ComboBoxTests/Given_ComboBox.cs +++ b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ComboBoxTests/Given_ComboBox.cs @@ -46,7 +46,7 @@ public void When_ComboBox_Is_First_Opening() { Setters = { new Setter("Template", t => - t.Template = Funcs.Create(() => grid) + t.Template = new ControlTemplate(() => grid) ) } }; diff --git a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ItemsControlTests/Given_ItemsControl.cs b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ItemsControlTests/Given_ItemsControl.cs index a93f4f88ebbe..36c09124a20b 100644 --- a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ItemsControlTests/Given_ItemsControl.cs +++ b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ItemsControlTests/Given_ItemsControl.cs @@ -89,7 +89,7 @@ public void When_TemplatedParent_Before_Loading() { Setters = { new Setter("Template", t => - t.Template = Funcs.Create(() => itemsPresenter) + t.Template = new ControlTemplate(() => itemsPresenter) ) } }; diff --git a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ListViewBaseTests/Given_ListViewBase.cs b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ListViewBaseTests/Given_ListViewBase.cs index 5703f14d59bf..f980d5a7188c 100644 --- a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ListViewBaseTests/Given_ListViewBase.cs +++ b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/ListViewBaseTests/Given_ListViewBase.cs @@ -15,6 +15,8 @@ using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Data; using FluentAssertions; +using Microsoft.UI.Xaml.Markup; +using Uno.UI.Helpers; namespace Uno.UI.Tests.ListViewBaseTests { @@ -690,21 +692,21 @@ public void When_NoItemTemplate() var SUT = new ListView() { Style = null, - ItemsPanel = new ItemsPanelTemplate(() => new StackPanel()), + ItemsPanel = XamlHelper.LoadXaml(""), ItemContainerStyle = BuildBasicContainerStyle(), ItemTemplate = null, ItemTemplateSelector = null, - Template = new ControlTemplate(() => new ItemsPresenter()), + Template = XamlHelper.LoadXaml(""), }; - SUT.ForceLoaded(); var source = new[] { "Item 1" }; - SUT.ItemsSource = source; + var tree = SUT.TreeGraph(); + var si = SUT.ContainerFromItem(source[0]) as ListViewItem; Assert.IsNotNull(si); Assert.AreEqual("Item 1", si.Content); @@ -759,43 +761,43 @@ public void When_ObservableVectorStringChanged() { var count = 0; var containerCount = 0; + using var dispose1 = SelfCountingGrid.HookCtor(() => count++); + using var dispose2 = SelfCountingGrid2.HookCtor(() => containerCount++); + var panel = new StackPanel(); panel.ForceLoaded(); var source = new ObservableVector() { "1", "2", "3" }; - Style BuildContainerStyle() => - new Style(typeof(Microsoft.UI.Xaml.Controls.ListViewItem)) - { - Setters = { - new Setter("Template", t => - t.Template = Funcs.Create(() => { - containerCount++; - return new Grid - { - Children = { - new ContentPresenter() - .Apply(p => { - p.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding(){ Path = "ContentTemplate", RelativeSource = RelativeSource.TemplatedParent }); - p.SetBinding(ContentPresenter.ContentProperty, new Binding(){ Path = "Content", RelativeSource = RelativeSource.TemplatedParent }); - }) - } - }; - }) - ) - } - }; + var xmlnses = new Dictionary + { + [string.Empty] = "http://schemas.microsoft.com/winfx/2006/xaml/presentation", + ["x"] = "http://schemas.microsoft.com/winfx/2006/xaml", + ["local"] = $"using:{typeof(SelfCountingGrid).Namespace}", + }; + Style BuildContainerStyle() => XamlHelper.LoadXaml + """, xmlnses); var SUT = new ListView() { ItemsPanelRoot = panel, InternalItemsPanelRoot = panel, ItemContainerStyle = BuildContainerStyle(), - ItemTemplate = new DataTemplate(() => - { - count++; - return new Border(); - }) + ItemTemplate = XamlHelper.LoadXaml("", xmlnses), }; Assert.AreEqual(0, count); @@ -824,26 +826,22 @@ Style BuildContainerStyle() => Assert.AreEqual(5, containerCount); } - private Style BuildBasicContainerStyle() => - new Style(typeof(Microsoft.UI.Xaml.Controls.ListViewItem)) - { - Setters = { - new Setter("Template", t => - t.Template = Funcs.Create(() => - new Grid - { - Children = { - new ContentPresenter() - .Apply(p => { - p.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding(){ Path = "ContentTemplate", RelativeSource = RelativeSource.TemplatedParent }); - p.SetBinding(ContentPresenter.ContentProperty, new Binding(){ Path = "Content", RelativeSource = RelativeSource.TemplatedParent }); - }) - } - } - ) - ) - } - }; + private Style BuildBasicContainerStyle() => XamlHelper.LoadXaml + """); } public class MyModel @@ -866,5 +864,42 @@ protected override void OnItemsChanged(object e) base.OnItemsChanged(e); } } + + public class SelfCountingGrid : Grid + { + public static int Count { get; private set; } + public static Action CtorCallback = null; + + public SelfCountingGrid() + { + Count++; + CtorCallback?.Invoke(); + } + + public static IDisposable RestartCounter() => HookCtor(null); + public static IDisposable HookCtor(Action callback) + { + (Count, CtorCallback) = (0, callback); + return new DisposableAction(() => (Count, CtorCallback) = (0, null)); + } + } + public class SelfCountingGrid2 : Grid + { + public static int Count { get; private set; } + public static Action CtorCallback = null; + + public SelfCountingGrid2() + { + Count++; + CtorCallback?.Invoke(); + } + + public static IDisposable RestartCounter() => HookCtor(null); + public static IDisposable HookCtor(Action callback) + { + (Count, CtorCallback) = (0, callback); + return new DisposableAction(() => (Count, CtorCallback) = (0, null)); + } + } } #endif diff --git a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/SelectorTests/Given_Selector.cs b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/SelectorTests/Given_Selector.cs index ac04c5212791..742214604946 100644 --- a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/SelectorTests/Given_Selector.cs +++ b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/SelectorTests/Given_Selector.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; +using Uno.UI.Helpers; namespace Uno.UI.Tests.Windows_UI_XAML_Controls.SelectorTests { @@ -221,7 +222,7 @@ public void When_SelectionChanged_And_SelectorItem_IsSelected_Changed() { var SUT = new Selector() { - ItemsPanel = new ItemsPanelTemplate(() => new StackPanel()), + ItemsPanel = XamlHelper.LoadXaml(""), Template = new ControlTemplate(() => new ItemsPresenter()), }; SUT.ForceLoaded(); diff --git a/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs b/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs index a753297968cf..8877c3c01cb9 100644 --- a/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs +++ b/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs @@ -108,7 +108,7 @@ public void When_MultipleBindings() var itemsPanel = listView?.ItemsPanel; Assert.IsNotNull(itemsPanel); - var content = ((IFrameworkTemplateInternal)itemsPanel).LoadContent() as StackPanel; + var content = ((IFrameworkTemplateInternal)itemsPanel).LoadContent(listView) as StackPanel; Assert.IsNotNull(content); Assert.AreEqual(content.Name, "InnerStackPanel");