[X] send tree changed events on parenting (#8760)

so thye will be triggered in all cases
This commit is contained in:
Stephane Delcroix 2019-12-06 05:04:49 +01:00 коммит произвёл Samantha Houts
Родитель 0250aefe57
Коммит ad78adb23f
9 изменённых файлов: 67 добавлений и 47 удалений

Просмотреть файл

@ -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"),

Просмотреть файл

@ -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();

Просмотреть файл

@ -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,

Просмотреть файл

@ -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; }
}
}

Просмотреть файл

@ -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;
}
}
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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))]