Skip to content

Commit

Permalink
Merge pull request #17645 from unoplatform/dev/xygu/20240703/template…
Browse files Browse the repository at this point in the history
…d-parent-rework-v3

feat!: templated-parent rework
  • Loading branch information
jeromelaban authored Oct 9, 2024
2 parents 09d5d7c + 4a9fdf1 commit 41f5e54
Show file tree
Hide file tree
Showing 170 changed files with 3,400 additions and 1,526 deletions.
26 changes: 26 additions & 0 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1910,11 +1910,37 @@
</Fields>

<Properties>
<!-- BEGIN templated-parent rework -->

<!-- HorizontalGridView -->
<Member fullName="System\.Func`1&lt;Android\.Views\.View&gt; Uno\.UI\.Controls\.HorizontalGridView::(Item|Header|Footer)Template\(\)" reason="Not in UWP" isRegex="true" />

<!-- END templated-parent rework -->
</Properties>

<Methods>
<Member fullName="System.Void Microsoft.Web.WebView2.Core.CoreWebView2.set_DocumentTitle(System.String value)" reason="Does not exist in UWP" />

<!-- BEGIN templated-parent rework -->

<!-- DependencyObject (codegen for all descendants) -->
<Member fullName=".*DependencyProperty .*\.get_TemplatedParentProperty\(\)" reason="Not in UWP" isRegex="true" />
<Member fullName=".*DependencyObject .*\.get_TemplatedParent\(\)" reason="Not in UWP" isRegex="true" />
<Member fullName="System\.Void .*\.set_TemplatedParent\((Microsoft|Windows)\.UI\.Xaml\.DependencyObject value\)" reason="Not in UWP" isRegex="true" />

<!-- templates: FrameworkTemplate, DataTemplate, ControlTemplate, ItemsPanelTemplate -->
<Member fullName="(?&lt;ReturnType&gt;(Microsoft|Windows)\.UI\.Xaml\.(DataTemplate|Controls\.(ControlTemplate|ItemsPanelTemplate))) \k&lt;ReturnType&gt;\.op_Implicit\(System\.Func`1&lt;.*&gt; obj\)" reason="Not in UWP" isRegex="true" />
<Member fullName="System\.Func`1&lt;.*&gt; (?&lt;DeclaringType&gt;(Microsoft|Windows)\.UI\.Xaml\.(FrameworkTemplate|DataTemplate|Controls\.(ControlTemplate|ItemsPanelTemplate)))\.op_Implicit\(\k&lt;DeclaringType&gt; obj\)" reason="Not in UWP" isRegex="true" />

<!-- HorizontalGridView -->
<Member fullName="System\.Func`1&lt;Android\.Views\.View&gt; Uno\.UI\.Controls\.HorizontalGridView\.get_(Item|Header|Footer)Template\(\)" reason="Not in UWP" isRegex="true" />
<Member fullName="System\.Void Uno\.UI\.Controls\.HorizontalGridView\.set_(Item|Header|Footer)Template\(System\.Func`1&lt;Android\.Views\.View&gt; value\)" reason="Not in UWP" isRegex="true" />

<!-- ViewExtensions -->
<Member fullName="System\.String Uno\.UI\.Extensions\.ViewExtensions\.TreeGraph\((?&lt;_View&gt;.+) reference, System\.Func`2&lt;\k&lt;_View&gt;,System\.String&gt; describe\)" isRegex="true" reason="Not in UWP" />

<!-- END templated-parent rework -->

<!-- BEGIN ComboBox.IsEditable -->
<Member fullName="System.Void Windows.UI.Xaml.Controls.Primitives.Selector.SetFocusedItem(System.Int32 index, System.Boolean shouldScrollIntoView, System.Boolean forceFocus, Windows.UI.Xaml.FocusState focusState, System.Boolean animateIfBringIntoView)" reason="Does not exist in UWP" />
<Member fullName="System.Void Windows.UI.Xaml.Controls.Primitives.Selector.SetFocusedItem(System.Int32 index, System.Boolean shouldScrollIntoView, System.Boolean forceFocus, Windows.UI.Xaml.FocusState focusState, System.Boolean animateIfBringIntoView, Windows.UI.Xaml.Input.FocusNavigationDirection focusNavigationDirection)" reason="Does not exist in UWP" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, },
Expand All @@ -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, },
Expand Down Expand Up @@ -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<SequenceItem> sequence)
{
//ReadTest(fileName);
#if DEBUG && false
var xml = GetXml(fileName);
var tokens = ReadAllTokens(fileName).ToArray();
#endif

var r = GetReader(fileName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,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;
Expand All @@ -158,7 +159,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;
Expand All @@ -169,7 +170,7 @@ private DependencyObjectStore __Store
{
if(__storeBackingField == null)
{
__storeBackingField = new DependencyObjectStore(this, DataContextProperty, TemplatedParentProperty);
__storeBackingField = new DependencyObjectStore(this, DataContextProperty);
__InitializeBinder();
}
return __storeBackingField;
Expand All @@ -184,6 +185,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;
Expand Down Expand Up @@ -266,31 +289,32 @@ internal protected virtual void OnDataContextChanged(DependencyPropertyChangedEv

#endregion

#region TemplatedParent DependencyProperty
#region TemplatedParent DependencyProperty // legacy api, should no longer to be used.

public DependencyObject TemplatedParent
[EditorBrowsable(EditorBrowsableState.Never)]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...
[EditorBrowsable(EditorBrowsableState.Never)]
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,
options: /*FrameworkPropertyMetadataOptions.Inherits | */FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.WeakStorage,
propertyChangedCallback: (s, e) => ((Inner)s).OnTemplatedParentChanged(e)
)
);


[EditorBrowsable(EditorBrowsableState.Never)]
internal protected virtual void OnTemplatedParentChanged(DependencyPropertyChangedEventArgs e)
{
__Store.SetTemplatedParent(e.NewValue as FrameworkElement);
OnTemplatedParentChangedPartial(e);
}

Expand Down Expand Up @@ -321,6 +345,7 @@ public void SetBindingValue(object value, [CallerMemberName] string propertyName

partial void OnDataContextChangedPartial(DependencyPropertyChangedEventArgs e);

[EditorBrowsable(EditorBrowsableState.Never)]
partial void OnTemplatedParentChangedPartial(DependencyPropertyChangedEventArgs e);

public global::Microsoft.UI.Xaml.Data.BindingExpression GetBindingExpression(DependencyProperty dependencyProperty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner)
) .GenericApply(__that, __nameScope, ((c6, __that, __nameScope) =>
{
global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c6, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L13:6");
Expand All @@ -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) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1>()).Build(__owner)
) .GenericApply(__that, __nameScope, ((c7, __that, __nameScope) =>
{
global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c7, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L42:8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner)
) .GenericApply(__that, __nameScope, ((c6, __that, __nameScope) =>
{
global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c6, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L13:6");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => new _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_TestReproMyResourceDictionarySC0().Build(__owner)
) )
;
}
Expand Down Expand Up @@ -178,7 +178,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) => new __Resources._MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionaryRDSC1().Build(__owner)
) ;

private global::Microsoft.UI.Xaml.ResourceDictionary _MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_ResourceDictionary;
Expand All @@ -197,7 +197,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) => new __Resources._MyResourceDictionary_92716e07ff456818f6d4125e055d4d57_MyResourceDictionaryRDSC2().Build(__owner)
) )
,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void InitializeComponent()
{
IsParsing = true,
Name = "inner2",
Template = new global::Microsoft.UI.Xaml.Controls.ControlTemplate(this , __owner => new _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0().Build(__owner)
Template = new global::Microsoft.UI.Xaml.Controls.ControlTemplate(this, (__owner) => new _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0().Build(__owner)
) ,
// Source 0\MainPage.xaml (Line 15:5)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => new _Binding_ElementName_In_Template_66bf0a54f1801c397a6fa4930a237eca_UnoUITestsWindows_UI_Xaml_DataBindingTestsControlsBinding_ElementName_In_TemplateSC0().Build(__owner)
) ,
// Source 0\Binding_ElementName_In_Template.xaml (Line 11:4)
}
Expand Down
Loading

0 comments on commit 41f5e54

Please sign in to comment.