From 5a9c4c32b0331b3e430ad5ff68f12e4ebd7d1f75 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 23 Nov 2020 13:53:46 +0800 Subject: [PATCH] style: use different icons for expanded/collapsed items --- src/UI/FolderDailog.xaml | 2 +- src/UI/FolderDailog.xaml.cs | 50 +++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/UI/FolderDailog.xaml b/src/UI/FolderDailog.xaml index 744c719d..ccc619e9 100644 --- a/src/UI/FolderDailog.xaml +++ b/src/UI/FolderDailog.xaml @@ -65,8 +65,8 @@ diff --git a/src/UI/FolderDailog.xaml.cs b/src/UI/FolderDailog.xaml.cs index 1f8c79e8..d915a294 100644 --- a/src/UI/FolderDailog.xaml.cs +++ b/src/UI/FolderDailog.xaml.cs @@ -1,19 +1,10 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace SourceGit.UI { @@ -29,9 +20,34 @@ namespace SourceGit.UI { /// Tree node. /// public class Node : INotifyPropertyChanged { + private bool isOpened = false; + + /// + /// Display name. + /// public string Name { get; set; } + + /// + /// Full path in file-system. + /// public string Path { get; set; } - public bool IsOpened { get; set; } + + /// + /// Is opened. + /// + public bool IsOpened { + get { return isOpened; } + set { + if (isOpened != value) { + isOpened = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsOpened")); + } + } + } + + /// + /// Children nodes. + /// public ObservableCollection Children { get; set; } /// @@ -48,7 +64,7 @@ namespace SourceGit.UI { public Node(string name, string path) { Name = name; Path = path; - IsOpened = false; + isOpened = false; Children = new ObservableCollection(); } @@ -174,12 +190,24 @@ namespace SourceGit.UI { var node = item.DataContext as Node; if (node == null) return; + node.IsOpened = true; foreach (var c in node.Children) { c.CollectChildren(); } e.Handled = true; } + + private void OnTreeNodeCollapsed(object sender, RoutedEventArgs e) { + var item = sender as TreeViewItem; + if (item == null) return; + + var node = item.DataContext as Node; + if (node == null) return; + + node.IsOpened = false; + e.Handled = true; + } #endregion } }