-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
112 lines (98 loc) · 4.21 KB
/
Program.cs
File metadata and controls
112 lines (98 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.ComponentModel;
using ConsoleFramework;
using ConsoleFramework.Controls;
using ConsoleFramework.Events;
namespace Examples.TreeView
{
class Program
{
public class Context : INotifyPropertyChanged {
private bool findItemAndRemoveRecursively(IList<TreeItem> items, TreeItem item) {
if (items.Contains(item)) {
items.Remove(item);
return true;
}
foreach (TreeItem treeItem in items) {
if (findItemAndRemoveRecursively(treeItem.Items, item)) return true;
}
return false;
}
public Context() {
removeCommand = new RelayCommand(o => {
if (SelectedItem != null) {
findItemAndRemoveRecursively(Items, SelectedItem);
}
}, o => {
return SelectedItem != null;
});
expandCollapseCommand = new RelayCommand(o => {
if (SelectedItem != null) {
SelectedItem.Expanded = !SelectedItem.Expanded;
}
}, o => SelectedItem != null && SelectedItem.HasChildren);
changeTitleCommand = new RelayCommand( o => {
if ( SelectedItem != null ) {
SelectedItem.Title = "Changed title";
}
}, o => SelectedItem != null );
}
public IList<TreeItem> Items;
private TreeItem selectedItem;
public TreeItem SelectedItem {
get {
return selectedItem;
}
set {
if (selectedItem != value) {
selectedItem = value;
raisePropertyChanged("SelectedItem");
raisePropertyChanged("SelectedItemTitle");
removeCommand.RaiseCanExecuteChanged();
expandCollapseCommand.RaiseCanExecuteChanged( );
changeTitleCommand.RaiseCanExecuteChanged( );
}
}
}
public String SelectedItemTitle {
get {
return selectedItem != null ? selectedItem.Title : null;
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void raisePropertyChanged(string propertyName) {
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
private readonly RelayCommand removeCommand;
public ICommand RemoveCommand {
get {
return removeCommand;
}
}
private readonly RelayCommand expandCollapseCommand;
public ICommand ExpandCollapseCommand {
get {
return expandCollapseCommand;
}
}
private readonly RelayCommand changeTitleCommand;
public ICommand ChangeTitleCommand {
get { return changeTitleCommand; }
}
}
public static void Main(string[] args) {
Context context = new Context();
WindowsHost windowsHost = (WindowsHost)ConsoleApplication.LoadFromXaml(
"Examples.TreeView.windows-host.xml", null);
Window mainWindow = (Window)ConsoleApplication.LoadFromXaml(
"Examples.TreeView.main.xml", context);
windowsHost.Show(mainWindow);
ConsoleFramework.Controls.TreeView tree = mainWindow.FindChildByName<ConsoleFramework.Controls.TreeView>("tree");
// todo : придумать способ для того, чтобы обходиться без такого костыля
context.Items = tree.Items;
ConsoleApplication.Instance.Run(windowsHost);
}
}
}