csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.3 KiB
67 lines
2.3 KiB
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using Avalonia.Collections;
|
|
|
|
namespace Avalonia.Controls
|
|
{
|
|
/// <summary>
|
|
/// A collection of <see cref="RowDefinition"/>s.
|
|
/// </summary>
|
|
public class RowDefinitions : AvaloniaList<RowDefinition>
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="RowDefinitions"/> class.
|
|
/// </summary>
|
|
public RowDefinitions()
|
|
{
|
|
ResetBehavior = ResetBehavior.Remove;
|
|
CollectionChanged += OnCollectionChanged;
|
|
this.TrackItemPropertyChanged(delegate { IsDirty = true; });
|
|
}
|
|
|
|
internal bool IsDirty { get; set; } = true;
|
|
internal Grid Parent { get; set; }
|
|
|
|
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
foreach (var nI in this.Select((d, i) => (d, i)))
|
|
nI.d._parentIndex = nI.i;
|
|
|
|
foreach (var nD in e.NewItems?.Cast<DefinitionBase>()
|
|
?? Enumerable.Empty<DefinitionBase>())
|
|
{
|
|
nD.Parent = this.Parent;
|
|
nD.OnEnterParentTree();
|
|
}
|
|
|
|
foreach (var oD in e.OldItems?.Cast<DefinitionBase>()
|
|
?? Enumerable.Empty<DefinitionBase>())
|
|
{
|
|
oD.Parent = null;
|
|
oD.OnExitParentTree();
|
|
}
|
|
|
|
IsDirty = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="RowDefinitions"/> class.
|
|
/// </summary>
|
|
/// <param name="s">A string representation of the row definitions.</param>
|
|
public RowDefinitions(string s)
|
|
: this()
|
|
{
|
|
AddRange(GridLength.ParseLengths(s).Select(x => new RowDefinition(x)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parses a string representation of row definitions collection.
|
|
/// </summary>
|
|
/// <param name="s">The row definitions string.</param>
|
|
/// <returns>The <see cref="RowDefinitions"/>.</returns>
|
|
public static RowDefinitions Parse(string s) => new RowDefinitions(s);
|
|
}
|
|
}
|