Browse Source

Trigger OnEnter/EnterParentTree on DefBase.

pull/2563/head
Jumar Macato 7 years ago
parent
commit
adbd42ed2d
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 10
      src/Avalonia.Controls/DefinitionBase.cs
  2. 37
      src/Avalonia.Controls/Grid.cs
  3. 15
      tests/Avalonia.Controls.UnitTests/SharedSizeScopeTests.cs

10
src/Avalonia.Controls/DefinitionBase.cs

@ -655,7 +655,7 @@ namespace Avalonia.Controls
/// <summary>
/// Collection of shared states objects for a single scope
/// </summary>
private class SharedSizeScope
internal class SharedSizeScope
{
/// <summary>
/// Returns SharedSizeState object for a given group.
@ -690,7 +690,7 @@ namespace Avalonia.Controls
/// <summary>
/// Implementation of per shared group state object
/// </summary>
private class SharedSizeState
internal class SharedSizeState
{
/// <summary>
/// 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.
/// <see cref="OnIsSharedSizeScopePropertyChanged"/>
/// </summary>
private static readonly AttachedProperty<SharedSizeScope> PrivateSharedSizeScopeProperty =
internal static readonly AttachedProperty<SharedSizeScope> PrivateSharedSizeScopeProperty =
AvaloniaProperty.RegisterAttached<DefinitionBase, Control, SharedSizeScope>(
"PrivateSharedSizeScope");
"PrivateSharedSizeScope",
defaultValue: null,
inherits: true);
/// <summary>
/// Shared size group property marks column / row definition as belonging to a group "Foo" or "Bar".

37
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
/// </remarks>
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<DefinitionBase>())
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);
}
/// <summary>
@ -969,8 +976,6 @@ namespace Avalonia.Controls
/// </remarks>
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<DefinitionBase>())
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);
}
/// <summary>

15
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]

Loading…
Cancel
Save