diff --git a/src/Avalonia.Controls/DefinitionBase.cs b/src/Avalonia.Controls/DefinitionBase.cs
index 2e0afc7fe7..0c696a1035 100644
--- a/src/Avalonia.Controls/DefinitionBase.cs
+++ b/src/Avalonia.Controls/DefinitionBase.cs
@@ -655,7 +655,7 @@ namespace Avalonia.Controls
///
/// Collection of shared states objects for a single scope
///
- private class SharedSizeScope
+ internal class SharedSizeScope
{
///
/// Returns SharedSizeState object for a given group.
@@ -690,7 +690,7 @@ namespace Avalonia.Controls
///
/// Implementation of per shared group state object
///
- private class SharedSizeState
+ internal class SharedSizeState
{
///
/// Default ctor.
@@ -900,9 +900,11 @@ namespace Avalonia.Controls
/// Private shared size scope property holds a collection of shared state objects for the a given shared size scope.
///
///
- private static readonly AttachedProperty PrivateSharedSizeScopeProperty =
+ internal static readonly AttachedProperty PrivateSharedSizeScopeProperty =
AvaloniaProperty.RegisterAttached(
- "PrivateSharedSizeScope");
+ "PrivateSharedSizeScope",
+ defaultValue: null,
+ inherits: true);
///
/// Shared size group property marks column / row definition as belonging to a group "Foo" or "Bar".
diff --git a/src/Avalonia.Controls/Grid.cs b/src/Avalonia.Controls/Grid.cs
index eaa7cc11c3..269d7a3093 100644
--- a/src/Avalonia.Controls/Grid.cs
+++ b/src/Avalonia.Controls/Grid.cs
@@ -7,6 +7,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Linq;
using System.Threading;
using Avalonia;
using Avalonia.Collections;
@@ -922,8 +923,6 @@ namespace Avalonia.Controls
///
private void ValidateDefinitionsUStructure()
{
-
-
if (ColumnDefinitionsDirty)
{
ExtendedData extData = ExtData;
@@ -937,8 +936,6 @@ namespace Avalonia.Controls
}
else
{
- // extData.ColumnDefinitions.InternalTrimToSize();
-
if (extData.ColumnDefinitions.Count == 0)
{
// if column definitions collection is empty
@@ -947,16 +944,26 @@ namespace Avalonia.Controls
}
else
{
+ foreach(var definition in extData.DefinitionsU
+ ?? Enumerable.Empty())
+ definition.OnExitParentTree();
+
extData.DefinitionsU = extData.ColumnDefinitions;
}
}
+ // adds index information.
+ for(int i = 0; i < extData.DefinitionsU.Count;i++)
+ {
+ var definition = extData.DefinitionsU[i];
+ definition.Index = i;
+ definition.OnEnterParentTree();
+ }
+
ColumnDefinitionsDirty = false;
}
Debug.Assert(ExtData.DefinitionsU != null && ExtData.DefinitionsU.Count > 0);
-
-
}
///
@@ -969,8 +976,6 @@ namespace Avalonia.Controls
///
private void ValidateDefinitionsVStructure()
{
-
-
if (RowDefinitionsDirty)
{
ExtendedData extData = ExtData;
@@ -984,8 +989,6 @@ namespace Avalonia.Controls
}
else
{
- // extData.RowDefinitions.InternalTrimToSize();
-
if (extData.RowDefinitions.Count == 0)
{
// if row definitions collection is empty
@@ -994,16 +997,26 @@ namespace Avalonia.Controls
}
else
{
+ foreach(var definition in extData.DefinitionsV
+ ?? Enumerable.Empty())
+ definition.OnExitParentTree();
+
extData.DefinitionsV = extData.RowDefinitions;
}
}
+ // adds index information.
+ for(int i = 0; i < extData.DefinitionsV.Count;i++)
+ {
+ var definition = extData.DefinitionsV[i];
+ definition.Index = i;
+ definition.OnEnterParentTree();
+ }
+
RowDefinitionsDirty = false;
}
Debug.Assert(ExtData.DefinitionsV != null && ExtData.DefinitionsV.Count > 0);
-
-
}
///
diff --git a/tests/Avalonia.Controls.UnitTests/SharedSizeScopeTests.cs b/tests/Avalonia.Controls.UnitTests/SharedSizeScopeTests.cs
index 467c25bfc6..12d4df32e5 100644
--- a/tests/Avalonia.Controls.UnitTests/SharedSizeScopeTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/SharedSizeScopeTests.cs
@@ -12,6 +12,11 @@ namespace Avalonia.Controls.UnitTests
{
public class SharedSizeScopeTests
{
+ public bool HasSharedSizeScope(Control control)
+ {
+ return control.GetValue(DefinitionBase.PrivateSharedSizeScopeProperty) != null;
+ }
+
[Fact]
public void All_Descendant_Grids_Are_Registered_When_Added_After_Setting_Scope()
{
@@ -23,7 +28,7 @@ namespace Avalonia.Controls.UnitTests
root.SetValue(Grid.IsSharedSizeScopeProperty, true);
root.Child = scope;
- Assert.All(grids, g => Assert.True(g.HasSharedSizeScope()));
+ Assert.All(grids, g => Assert.True(HasSharedSizeScope(g)));
}
[Fact]
@@ -37,7 +42,7 @@ namespace Avalonia.Controls.UnitTests
root.Child = scope;
root.SetValue(Grid.IsSharedSizeScopeProperty, true);
- Assert.All(grids, g => Assert.True(g.HasSharedSizeScope()));
+ Assert.All(grids, g => Assert.True(HasSharedSizeScope(g)));
}
[Fact]
@@ -51,10 +56,10 @@ namespace Avalonia.Controls.UnitTests
root.SetValue(Grid.IsSharedSizeScopeProperty, true);
root.Child = scope;
- Assert.All(grids, g => Assert.True(g.HasSharedSizeScope()));
+ Assert.All(grids, g => Assert.True(HasSharedSizeScope(g)));
root.SetValue(Grid.IsSharedSizeScopeProperty, false);
- Assert.All(grids, g => Assert.False(g.HasSharedSizeScope()));
- Assert.Equal(null, root.GetValue(Grid.PrivateSharedSizeScopeProperty));
+ Assert.All(grids, g => Assert.False(HasSharedSizeScope(g)));
+ Assert.Equal(null, root.GetValue(DefinitionBase.PrivateSharedSizeScopeProperty));
}
[Fact]