style<FolderDialog>: use different icons for expanded/collapsed items

This commit is contained in:
leo 2020-11-23 13:53:46 +08:00
parent d6526e7907
commit 5a9c4c32b0
2 changed files with 40 additions and 12 deletions

View file

@ -65,8 +65,8 @@
<TreeView x:Name="treePath" FontFamily="Consolas" PreviewMouseWheel="OnTreeMouseWheel" SelectedItemChanged="OnTreeSelectedChanged"> <TreeView x:Name="treePath" FontFamily="Consolas" PreviewMouseWheel="OnTreeMouseWheel" SelectedItemChanged="OnTreeSelectedChanged">
<TreeView.ItemContainerStyle> <TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource Style.TreeView.ItemContainerStyle}"> <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource Style.TreeView.ItemContainerStyle}">
<Setter Property="IsExpanded" Value="{Binding IsOpened, Mode=TwoWay}"/>
<EventSetter Event="Expanded" Handler="OnTreeNodeExpanded"/> <EventSetter Event="Expanded" Handler="OnTreeNodeExpanded"/>
<EventSetter Event="Collapsed" Handler="OnTreeNodeCollapsed"/>
</Style> </Style>
</TreeView.ItemContainerStyle> </TreeView.ItemContainerStyle>

View file

@ -1,19 +1,10 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace SourceGit.UI { namespace SourceGit.UI {
@ -29,9 +20,34 @@ namespace SourceGit.UI {
/// Tree node. /// Tree node.
/// </summary> /// </summary>
public class Node : INotifyPropertyChanged { public class Node : INotifyPropertyChanged {
private bool isOpened = false;
/// <summary>
/// Display name.
/// </summary>
public string Name { get; set; } public string Name { get; set; }
/// <summary>
/// Full path in file-system.
/// </summary>
public string Path { get; set; } public string Path { get; set; }
public bool IsOpened { get; set; }
/// <summary>
/// Is opened.
/// </summary>
public bool IsOpened {
get { return isOpened; }
set {
if (isOpened != value) {
isOpened = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsOpened"));
}
}
}
/// <summary>
/// Children nodes.
/// </summary>
public ObservableCollection<Node> Children { get; set; } public ObservableCollection<Node> Children { get; set; }
/// <summary> /// <summary>
@ -48,7 +64,7 @@ namespace SourceGit.UI {
public Node(string name, string path) { public Node(string name, string path) {
Name = name; Name = name;
Path = path; Path = path;
IsOpened = false; isOpened = false;
Children = new ObservableCollection<Node>(); Children = new ObservableCollection<Node>();
} }
@ -174,12 +190,24 @@ namespace SourceGit.UI {
var node = item.DataContext as Node; var node = item.DataContext as Node;
if (node == null) return; if (node == null) return;
node.IsOpened = true;
foreach (var c in node.Children) { foreach (var c in node.Children) {
c.CollectChildren(); c.CollectChildren();
} }
e.Handled = true; 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 #endregion
} }
} }