-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
118 lines (97 loc) · 3.61 KB
/
MainWindow.xaml.cs
File metadata and controls
118 lines (97 loc) · 3.61 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
113
114
115
116
117
118
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using ComboBox = System.Windows.Controls.ComboBox;
using Binding = System.Windows.Data.Binding;
using System.Transactions;
namespace RevitAddIn_MyProject
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window, IDisposable
{
private DataManager _DataManager;
public MainWindow()
{
InitializeComponent();
}
public MainWindow(DataManager dataManager)
{
InitializeComponent();
_DataManager = dataManager;
levelComboBox.ItemsSource = _DataManager.Levels;
levelComboBox.DisplayMemberPath = "Name";
levelComboBox.SelectedItem = _DataManager.CurrentLevel;
spacesListView.DataContext = _DataManager.SpaceCollection;
_ = spacesListView.SetBinding(ItemsControl.ItemsSourceProperty, new Binding());
zonesTreeView.DataContext = _DataManager.ZoneCollection;
_ = zonesTreeView.SetBinding(ItemsControl.ItemsSourceProperty, new Binding());
}
public void Dispose() { }
private void LevelComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_DataManager.CurrentLevel = levelComboBox.SelectedItem as Level;
}
private void CreateSpacesButton_Click(object sender, RoutedEventArgs e)
{
_DataManager.CreateSpaces();
}
private void CreateZoneButton_Click(object sender, RoutedEventArgs e)
{
_DataManager.CreateZone();
}
private void ZonesTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (e.NewValue is ZoneSpacesNode)
{
editZoneButton.IsEnabled = true;
}
else
{
editZoneButton.IsEnabled = false;
}
}
private void OK_Button_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
private void Cancel_Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void EditZoneButton_Click(object sender, RoutedEventArgs e)
{
ZoneSpacesNode zoneSpacesNode= zonesTreeView.SelectedItem as ZoneSpacesNode;
try
{
SubTransaction subTransaction = new SubTransaction(_DataManager.CommandData.Application.ActiveUIDocument.Document);
_ = subTransaction.Start();
bool? dialogResult = default;
using (EditZoneWindow editZoneWindow = new EditZoneWindow(_DataManager, zoneSpacesNode))
{
dialogResult = editZoneWindow.ShowDialog();
}
if (dialogResult == true)
{
_ = subTransaction.Commit();
_DataManager.UpdateSpaceDictionary();
_DataManager.UpdateZoneDictionary();
_DataManager.UpdateObservableCollections();
}
else
{
_ = subTransaction.RollBack();
}
}
catch (Exception ex)
{
_ = MessageBox.Show(ex.Message);
}
}
}
}