Skip to content

Commit

Permalink
fix: Executing OnPropertyChanged, Style incompatibilities, vector beh…
Browse files Browse the repository at this point in the history
…avior alignment
  • Loading branch information
MartinZikmund committed Sep 11, 2020
1 parent ecb8b09 commit 5a44136
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 169 deletions.
2 changes: 0 additions & 2 deletions src/Uno.Foundation/Collections/ObservableVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public virtual void RemoveAt(int index)

IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator();

internal List<T> GetVectorInnerImpl() => _list;

private void RaiseVectorChanged(CollectionChange change, int index)
{
VectorChanged?.Invoke(this, new VectorChangedEventArgs(change, (uint)index));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal void InsertAt(int index, object item)
{
if (!Contains(item))
{
GetVectorInnerImpl().Insert(index, item);
base.Insert(index, item);

// Keep SelectedNodes and SelectedItems in sync
var viewModel = m_viewModel;
Expand Down Expand Up @@ -55,7 +55,7 @@ internal void SetAt(int index, object item)

public override void RemoveAt(int index)
{
GetVectorInnerImpl().RemoveAt(index);
base.RemoveAt(index);

// Keep SelectedNodes and SelectedItems in sync
var viewModel = m_viewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public override TreeViewNode this[int index]
}

public override void RemoveAt(int index)
{
var inner = GetVectorInnerImpl();
var oldNode = inner[index];
{
var oldNode = base[index];
// UpdateNodeSelection will call RemoveAtCore
UpdateSelection(oldNode, TreeNodeSelectionState.UnSelected);
}
Expand Down Expand Up @@ -89,7 +88,7 @@ public override void Clear()
// If you want to update vector content without notifying TreeViewNodes, use "core" version of the methods.
internal void InsertAtCore(int index, TreeViewNode node)
{
GetVectorInnerImpl().Insert(index, node);
base.Insert(index, node);

// Keep SelectedItems and SelectedNodes in sync
var viewModel = m_viewModel;
Expand All @@ -110,7 +109,7 @@ internal void InsertAtCore(int index, TreeViewNode node)

internal void RemoveAtCore(int index)
{
GetVectorInnerImpl().RemoveAt(index);
base.RemoveAt(index);

// Keep SelectedItems and SelectedNodes in sync
var viewModel = m_viewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Microsoft.UI.Xaml.Controls
{
public partial class TreeView
public partial class TreeView
{
public bool CanDragItems
{
Expand Down Expand Up @@ -76,7 +76,7 @@ public TreeViewSelectionMode SelectionMode
DependencyProperty.Register(nameof(ItemContainerTransitions), typeof(TransitionCollection), typeof(TreeView), new PropertyMetadata(null));

public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register(nameof(ItemsSource), typeof(object), typeof(TreeView), new PropertyMetadata(null));
DependencyProperty.Register(nameof(ItemsSource), typeof(object), typeof(TreeView), new PropertyMetadata(null, OnItemsSourcePropertyChanged));

public static readonly DependencyProperty ItemTemplateProperty =
DependencyProperty.Register(nameof(ItemTemplate), typeof(DataTemplate), typeof(TreeView), new PropertyMetadata(null));
Expand All @@ -85,6 +85,22 @@ public TreeViewSelectionMode SelectionMode
DependencyProperty.Register(nameof(ItemTemplateSelector), typeof(DataTemplateSelector), typeof(TreeView), new PropertyMetadata(null));

public static readonly DependencyProperty SelectionModeProperty =
DependencyProperty.Register(nameof(SelectionMode), typeof(TreeViewSelectionMode), typeof(TreeView), new PropertyMetadata(TreeViewSelectionMode.Single));
DependencyProperty.Register(nameof(SelectionMode), typeof(TreeViewSelectionMode), typeof(TreeView), new PropertyMetadata(TreeViewSelectionMode.Single, OnSelectionModePropertyChanged));

private static void OnItemsSourcePropertyChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args)
{
var owner = (TreeView)sender;
owner.OnPropertyChanged(args);
}

private static void OnSelectionModePropertyChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args)
{
var owner = (TreeView)sender;
owner.OnPropertyChanged(args);
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI/Microsoft/UI/Xaml/Controls/TreeView/TreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TreeView()
m_rootNode = new TreeViewNode();
m_pendingSelectedNodes = new List<TreeViewNode>();

this.RegisterDisposablePropertyChangedCallback((s, p, e) => OnPropertyChanged(e));
//this.RegisterDisposablePropertyChangedCallback((s, p, e) => OnPropertyChanged(e));
}

internal TreeViewList ListControl { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Brush GlyphBrush
get { return (Brush)GetValue(GlyphBrushProperty); }
set { SetValue(GlyphBrushProperty, value); }
}

public double GlyphOpacity
{
get { return (double)GetValue(GlyphOpacityProperty); }
Expand Down Expand Up @@ -75,15 +75,39 @@ public TreeViewItemTemplateSettings TreeViewItemTemplateSettings
DependencyProperty.Register(nameof(GlyphSize), typeof(double), typeof(TreeViewItem), new PropertyMetadata(0));

public static readonly DependencyProperty HasUnrealizedChildrenProperty =
DependencyProperty.Register(nameof(HasUnrealizedChildren), typeof(bool), typeof(TreeViewItem), new PropertyMetadata(false));
DependencyProperty.Register(nameof(HasUnrealizedChildren), typeof(bool), typeof(TreeViewItem), new PropertyMetadata(false, OnHasUnrealizedChildrenPropertyChanged));

public static readonly DependencyProperty IsExpandedProperty =
DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(TreeViewItem), new PropertyMetadata(false));
DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(TreeViewItem), new PropertyMetadata(false, OnIsExpandedPropertyChanged));

public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register(nameof(ItemsSource), typeof(object), typeof(TreeViewItem), new PropertyMetadata(null));
DependencyProperty.Register(nameof(ItemsSource), typeof(object), typeof(TreeViewItem), new PropertyMetadata(null, OnItemsSourcePropertyChanged));

public static readonly DependencyProperty TreeViewItemTemplateSettingsProperty =
DependencyProperty.Register(nameof(TreeViewItemTemplateSettings), typeof(TreeViewItemTemplateSettings), typeof(TreeViewItem), new PropertyMetadata(null));

private static void OnHasUnrealizedChildrenPropertyChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args)
{
var owner = (TreeViewItem)sender;
owner.OnPropertyChanged(args);
}

private static void OnIsExpandedPropertyChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args)
{
var owner = (TreeViewItem)sender;
owner.OnPropertyChanged(args);
}

private static void OnItemsSourcePropertyChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args)
{
var owner = (TreeViewItem)sender;
owner.OnPropertyChanged(args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public TreeViewItem()
DefaultStyleKey = typeof(TreeViewItem);
SetValue(TreeViewItemTemplateSettingsProperty, new TreeViewItemTemplateSettings());

this.RegisterDisposablePropertyChangedCallback((s, p, e) => OnPropertyChanged(e));
//this.RegisterDisposablePropertyChangedCallback((s, p, e) => OnPropertyChanged(e));
}

protected override void OnKeyDown(KeyRoutedEventArgs e)
Expand Down
Loading

0 comments on commit 5a44136

Please sign in to comment.