Sun, 18 Sep 2016 08:39:37 +0200
detaching variables correctly
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | using System; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | using System.Collections.Generic; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | using System.Linq; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | using System.Text; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | using System.Threading; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | using System.Threading.Tasks; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | using System.Windows; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | using System.Windows.Controls; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | namespace UI |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | { |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
12 | public class MainWindow : Window, Container |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
13 | { |
85
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
14 | public Layout Layout |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
15 | { |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
16 | get |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
17 | { |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
18 | return Container.Layout; |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
19 | } |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
20 | set |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
21 | { |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
22 | Container.Layout = value; |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
23 | } |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
24 | } |
91f45354d1e2
added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
25 | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
26 | public IntPtr Object; |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
27 | public Container Container; |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
28 | |
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
29 | public MainWindow(String title, IntPtr uiobj) |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | { |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | Title = title; |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
32 | Object = uiobj; |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | Width = 300; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | Height = 300; |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
35 | |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
36 | Grid windowGrid = new Grid(); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
37 | ColumnDefinition column = new ColumnDefinition(); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
38 | column.Width = new GridLength(1, GridUnitType.Star); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
39 | windowGrid.ColumnDefinitions.Add(column); |
84
a56c2baa9429
added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
40 | this.AddChild(windowGrid); |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
41 | int rowIndex = 0; |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
42 | |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
43 | // menu |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
44 | Application app = Application.GetInstance(); |
89
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
45 | if (!app.Menu.IsEmpty()) |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
46 | { |
89
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
47 | System.Windows.Controls.Menu menu = app.Menu.CreateMenu(uiobj); |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
48 | |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
49 | RowDefinition menuRow = new RowDefinition(); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
50 | menuRow.Height = GridLength.Auto; |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
51 | windowGrid.RowDefinitions.Add(menuRow); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
52 | |
89
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
53 | Grid.SetRow(menu, rowIndex); |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
54 | Grid.SetColumn(menu, 0); |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
55 | windowGrid.Children.Add(menu); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
56 | rowIndex++; |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
57 | } |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
58 | |
89
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
59 | // toolbar |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
60 | if(app.ToolBar.HasItems()) |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
61 | { |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
62 | System.Windows.Controls.ToolBarTray tray = app.ToolBar.CreateToolBarTray(uiobj); |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
63 | RowDefinition menuRow = new RowDefinition(); |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
64 | menuRow.Height = GridLength.Auto; |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
65 | windowGrid.RowDefinitions.Add(menuRow); |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
66 | |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
67 | Grid.SetRow(tray, rowIndex); |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
68 | Grid.SetColumn(tray, 0); |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
69 | windowGrid.Children.Add(tray); |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
70 | rowIndex++; |
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
71 | } |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
72 | |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
73 | // content |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
74 | RowDefinition contentRow = new RowDefinition(); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
75 | contentRow.Height = new GridLength(1, GridUnitType.Star); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
76 | windowGrid.RowDefinitions.Add(contentRow); |
84
a56c2baa9429
added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
77 | BoxContainer vbox = new BoxContainer(BoxOrientation.VERTICAL); |
a56c2baa9429
added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
78 | Grid.SetColumn(vbox, 0); |
a56c2baa9429
added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
79 | Grid.SetRow(vbox, rowIndex); |
a56c2baa9429
added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
80 | windowGrid.Children.Add(vbox); |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
81 | rowIndex++; |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
82 | |
84
a56c2baa9429
added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
83 | Container = vbox; |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
84 | |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
85 | Closed += CloseEvent; |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
88 | public static MainWindow CreateMainWindow(String title, IntPtr uiobj) |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | { |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
90 | return Application.GetInstance().Exec<MainWindow>(() => new MainWindow(title, uiobj)); |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | public void ShowWindow() |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | { |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | Application.GetInstance().Exec(() => this.Show()); |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
96 | Application.GetInstance().AddWindow(this); |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
97 | } |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
98 | |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
99 | public void CloseEvent(object sender, System.EventArgs e) |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
100 | { |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
101 | Application.GetInstance().RemoveWindow(this); |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | } |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
103 | |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
104 | public void Add(UIElement control, bool fill) |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
105 | { |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
106 | Container.Add(control, fill); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
107 | } |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | } |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | } |