Skip to content

Commit

Permalink
Fix #292: Tree view items are not indented when created from code-behind
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Mar 23, 2021
1 parent f493a70 commit 9ccb428
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions ModernWpf/Controls/Primitives/TreeViewItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,25 @@ private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyCha
var treeViewItem = (TreeViewItem)d;
if ((bool)e.NewValue)
{
if (treeViewItem.IsInitialized)
treeViewItem.IsVisibleChanged += OnTreeViewItemIsVisibleChanged;
if (treeViewItem.IsVisible)
{
UpdateIndentation(treeViewItem);
}
else
{
treeViewItem.Initialized += OnTreeViewItemInitialized;
}
}
else
{
treeViewItem.Initialized -= OnTreeViewItemInitialized;
treeViewItem.IsVisibleChanged -= OnTreeViewItemIsVisibleChanged;
treeViewItem.ClearValue(IndentationPropertyKey);
}
}

private static void OnTreeViewItemInitialized(object sender, System.EventArgs e)
private static void OnTreeViewItemIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var treeViewItem = (TreeViewItem)sender;
treeViewItem.Initialized -= OnTreeViewItemInitialized;
UpdateIndentation(treeViewItem);
if ((bool)e.NewValue)
{
UpdateIndentation((TreeViewItem)sender);
}
}

#endregion
Expand Down

0 comments on commit 9ccb428

Please sign in to comment.