[X] send tree changed events on parenting (#8760)
authorStephane Delcroix <stephane@delcroix.org>
Fri, 6 Dec 2019 04:04:49 +0000 (05:04 +0100)
committerSamantha Houts <samhouts@users.noreply.github.com>
Fri, 6 Dec 2019 04:04:49 +0000 (20:04 -0800)
so thye will be triggered in all cases

Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
Xamarin.Forms.Core/Element.cs
Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
Xamarin.Forms.Core/Xaml/Diagnostics/DebuggerHelper.cs [moved from Xamarin.Forms.Xaml/Diagnostics/DebuggerHelper.cs with 100% similarity]
Xamarin.Forms.Core/Xaml/Diagnostics/VisualDiagnostics.cs [moved from Xamarin.Forms.Xaml/Diagnostics/VisualDiagnostics.cs with 58% similarity]
Xamarin.Forms.Core/Xaml/Diagnostics/VisualTreeChangeEventArgs.cs [new file with mode: 0644]
Xamarin.Forms.Core/Xaml/Diagnostics/XamlSourceInfo.cs [new file with mode: 0644]
Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
Xamarin.Forms.Xaml/Properties/AssemblyInfo.cs

index ebe618c..be1f4d1 100644 (file)
@@ -931,7 +931,7 @@ namespace Xamarin.Forms.Build.Tasks
                        yield return Create(Ldc_I4, lineInfo.LineNumber);                               //lineNumber
                        yield return Create(Ldc_I4, lineInfo.LinePosition);             //linePosition
 
-                       yield return Create(Call, module.ImportMethodReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Diagnostics", "VisualDiagnostics"),
+                       yield return Create(Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml.Diagnostics", "VisualDiagnostics"),
                                                                                                                                   methodName: "RegisterSourceInfo",
                                                                                                                                   parameterTypes: new[] {
                                                                                                                                           ("mscorlib", "System", "Object"),
index b96b0a5..84599f0 100644 (file)
@@ -5,6 +5,7 @@ using System.Collections.Specialized;
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
 using Xamarin.Forms.Internals;
+using Xamarin.Forms.Xaml.Diagnostics;
 
 namespace Xamarin.Forms
 {
@@ -200,6 +201,8 @@ namespace Xamarin.Forms
                                        SetInheritedBindingContext(this, null);
                                }
 
+                               VisualDiagnostics.SendVisualTreeChanged(this, value);
+
                                OnParentSet();
 
                                OnPropertyChanged();
index f7abdab..4be554b 100644 (file)
@@ -20,6 +20,9 @@
                <PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
                <PackageReference Include="System.ValueTuple" Version="4.5.0" />
        </ItemGroup>    
+       <ItemGroup>
+         <Folder Include="Xaml\Diagnostics\" />
+       </ItemGroup>
        <PropertyGroup>
     <GitInfoReportImportance>high</GitInfoReportImportance>
   </PropertyGroup>
@@ -1,5 +1,6 @@
 // Copyright (c) Microsoft Corporation.
 // Licensed under the MIT License.
+
 using System;
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
@@ -28,43 +29,6 @@ namespace Xamarin.Forms.Xaml.Diagnostics
                public static XamlSourceInfo GetXamlSourceInfo(object obj) => sourceInfos.TryGetValue(obj, out var sourceinfo) ? sourceinfo : null;
        }
 
-       public class XamlSourceInfo
-       {
-               public XamlSourceInfo(Uri sourceUri, int lineNumber, int linePosition)
-               {
-                       SourceUri = sourceUri;
-                       LineNumber = lineNumber;
-                       LinePosition = linePosition;
-               }
-
-               public Uri SourceUri { get; }
-               public int LineNumber { get; }
-               public int LinePosition { get; }
-
-               public void Deconstruct(out Uri sourceUri, out int lineNumber, out int linePosition)
-               {
-                       sourceUri = SourceUri;
-                       lineNumber = LineNumber;
-                       linePosition = LinePosition;
-               }
-       }
-
-       public class VisualTreeChangeEventArgs : EventArgs
-       {
-               public VisualTreeChangeEventArgs(object parent, object child, int childIndex, VisualTreeChangeType changeType)
-               {
-                       Parent = parent;
-                       Child = child;
-                       ChildIndex = childIndex;
-                       ChangeType = changeType;
-               }
-
-               public object Parent { get; }
-               public object Child { get; }
-               public int ChildIndex { get; }
-               public VisualTreeChangeType ChangeType { get; }
-       }
-
        public enum VisualTreeChangeType
        {
                Add = 0,
diff --git a/Xamarin.Forms.Core/Xaml/Diagnostics/VisualTreeChangeEventArgs.cs b/Xamarin.Forms.Core/Xaml/Diagnostics/VisualTreeChangeEventArgs.cs
new file mode 100644 (file)
index 0000000..5fbe231
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using System;
+
+namespace Xamarin.Forms.Xaml.Diagnostics
+{
+       public class VisualTreeChangeEventArgs : EventArgs
+       {
+               public VisualTreeChangeEventArgs(object parent, object child, int childIndex, VisualTreeChangeType changeType)
+               {
+                       Parent = parent;
+                       Child = child;
+                       ChildIndex = childIndex;
+                       ChangeType = changeType;
+               }
+
+               public object Parent { get; }
+               public object Child { get; }
+               public int ChildIndex { get; }
+               public VisualTreeChangeType ChangeType { get; }
+       }
+}
diff --git a/Xamarin.Forms.Core/Xaml/Diagnostics/XamlSourceInfo.cs b/Xamarin.Forms.Core/Xaml/Diagnostics/XamlSourceInfo.cs
new file mode 100644 (file)
index 0000000..4060526
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using System;
+
+namespace Xamarin.Forms.Xaml.Diagnostics
+{
+       public class XamlSourceInfo
+       {
+               public XamlSourceInfo(Uri sourceUri, int lineNumber, int linePosition)
+               {
+                       SourceUri = sourceUri;
+                       LineNumber = lineNumber;
+                       LinePosition = linePosition;
+               }
+
+               public Uri SourceUri { get; }
+               public int LineNumber { get; }
+               public int LinePosition { get; }
+
+               public void Deconstruct(out Uri sourceUri, out int lineNumber, out int linePosition)
+               {
+                       sourceUri = SourceUri;
+                       lineNumber = LineNumber;
+                       linePosition = LinePosition;
+               }
+       }
+}
index 705e3f6..ce051ea 100644 (file)
@@ -346,28 +346,22 @@ namespace Xamarin.Forms.Xaml
 
                        //If it's a BindableProberty, SetValue
                        if (xpe == null && TrySetValue(xamlelement, property, attached, value, lineInfo, serviceProvider, out xpe)) {
-                               if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path) {
+                               if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path)
                                        VisualDiagnostics.RegisterSourceInfo(value, new Uri(path, UriKind.Relative), ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
-                                       VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
-                               }
                                return;
                        }
 
                        //If we can assign that value to a normal property, let's do it
                        if (xpe == null && TrySetProperty(xamlelement, localName, value, lineInfo, serviceProvider, context, out xpe)) {
-                               if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path) {
+                               if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path)
                                        VisualDiagnostics.RegisterSourceInfo(value, new Uri(path, UriKind.Relative), ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
-                                       VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
-                               }
                                return;
                        }
 
                        //If it's an already initialized property, add to it
                        if (xpe == null && TryAddToProperty(xamlelement, propertyName, value, xKey, lineInfo, serviceProvider, context, out xpe)) {
-                               if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path) {
+                               if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path)
                                        VisualDiagnostics.RegisterSourceInfo(value, new Uri(path, UriKind.Relative), ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
-                                       VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
-                               }
                                return;
                        }
 
index 302cfc8..e4fb3cb 100644 (file)
@@ -23,3 +23,8 @@ using Xamarin.Forms.Internals;
 #pragma warning disable CS0612 // Type or member is obsolete
 [assembly: TypeForwardedTo(typeof(Xamarin.Forms.Xaml.Internals.INameScopeProvider))]
 #pragma warning restore CS0612 // Type or member is obsolete
+
+[assembly: TypeForwardedTo(typeof(Xamarin.Forms.Xaml.Diagnostics.DebuggerHelper))]
+[assembly: TypeForwardedTo(typeof(Xamarin.Forms.Xaml.Diagnostics.VisualDiagnostics))]
+[assembly: TypeForwardedTo(typeof(Xamarin.Forms.Xaml.Diagnostics.VisualTreeChangeEventArgs))]
+[assembly: TypeForwardedTo(typeof(Xamarin.Forms.Xaml.Diagnostics.XamlSourceInfo))]