Skip to content

Commit

Permalink
change: remove TreeListView _root
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Sep 19, 2024
1 parent d0990cc commit 88e48df
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Wpf.Ui.Violeta/Controls/TreeListView/TreeListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public ITreeModel Model
}

public static readonly DependencyProperty ModelProperty =
DependencyProperty.Register(nameof(Model), typeof(ITreeModel), typeof(TreeListView), new PropertyMetadata(null!, PropertyChangedCallback));
DependencyProperty.Register(nameof(Model), typeof(ITreeModel), typeof(TreeListView), new PropertyMetadata(null!, ModelChangedCallback));

public static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
public static void ModelChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is TreeListView self)
{
self._root.Children.Clear();
self.Root.Children.Clear();
self.Rows.Clear();
self.CreateChildrenNodes(self._root);
self.CreateChildrenNodes(self.Root);
}
}

Expand All @@ -47,13 +47,11 @@ public CornerRadius CornerRadius
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register(nameof(CornerRadius), typeof(CornerRadius), typeof(TreeListView), new PropertyMetadata(new CornerRadius(3)));

private TreeNode _root;

internal TreeNode Root => _root;
internal TreeNode Root { get; set; } = null!;

public ReadOnlyCollection<TreeNode> Nodes => Root.Nodes;

internal TreeNode? PendingFocusNode { get; set; }
internal TreeNode? PendingFocusNode { get; set; } = null;

public ICollection<TreeNode> SelectedNodes => SelectedItems.Cast<TreeNode>().ToArray();

Expand All @@ -62,7 +60,7 @@ public CornerRadius CornerRadius
public TreeListView()
{
Rows = [];
_root = new TreeNode(this, null!)
Root = new TreeNode(this, null!)
{
IsExpanded = true
};
Expand Down Expand Up @@ -142,7 +140,7 @@ internal void CreateChildrenNodes(TreeNode node)
private void CreateChildrenRows(TreeNode node)
{
int index = Rows.IndexOf(node);
if (index >= 0 || node == _root) // ignore invisible nodes
if (index >= 0 || node == Root) // ignore invisible nodes
{
var nodes = node.AllVisibleChildren.ToArray();
Rows.InsertRange(index + 1, nodes);
Expand All @@ -152,7 +150,7 @@ private void CreateChildrenRows(TreeNode node)
internal void DropChildrenRows(TreeNode node, bool removeParent)
{
int start = Rows.IndexOf(node);
if (start >= 0 || node == _root) // ignore invisible nodes
if (start >= 0 || node == Root) // ignore invisible nodes
{
int count = node.VisibleChildrenCount;
if (removeParent)
Expand Down

0 comments on commit 88e48df

Please sign in to comment.