-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
203 lines (191 loc) · 9.19 KB
/
Program.cs
File metadata and controls
203 lines (191 loc) · 9.19 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using ConsoleFramework;
using ConsoleFramework.Controls;
using ConsoleFramework.Core;
using ConsoleFramework.Xaml;
using Xaml;
namespace Examples
{
internal class Program
{
class MyDataContext : INotifyPropertyChanged
{
private string str;
public String Str {
get { return str; }
set {
if ( str != value ) {
str = value;
raisePropertyChanged( "Str" );
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void raisePropertyChanged( string propertyName ) {
PropertyChangedEventHandler handler = PropertyChanged;
if ( handler != null ) handler( this, new PropertyChangedEventArgs( propertyName ) );
}
}
private static void Main(string[] args) {
// Control window = ConsoleApplication.LoadFromXaml( "ConsoleFramework.Layout.xml", null );
//// window.FindChildByName< TextBlock >( "text" ).MouseDown += ( sender, eventArgs ) => {
//// window.FindChildByName< TextBlock >( "text" ).Text = "F";
//// eventArgs.Handled = true;
//// };
//// window.MouseDown += ( sender, eventArgs ) => {
//// window.Width = window.ActualWidth + 3;
//// window.Invalidate( );
//// };
// ConsoleApplication.Instance.Run( window );
// return;
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Examples.GridTest.xml";
Window createdFromXaml;
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
MyDataContext dataContext = new MyDataContext( );
dataContext.Str = "Введите заголовок";
createdFromXaml = XamlParser.CreateFromXaml<Window>(result, dataContext, new List<string>()
{
"clr-namespace:Xaml;assembly=Xaml",
"clr-namespace:ConsoleFramework.Xaml;assembly=ConsoleFramework",
"clr-namespace:ConsoleFramework.Controls;assembly=ConsoleFramework",
});
}
// ConsoleApplication.Instance.Run(createdFromXaml);
// return;
using (ConsoleApplication application = ConsoleApplication.Instance) {
Panel panel = new Panel();
panel.Name = "panel1";
panel.HorizontalAlignment = HorizontalAlignment.Center;
panel.VerticalAlignment = VerticalAlignment.Stretch;
panel.XChildren.Add(new TextBlock() {
Name = "label1",
Text = "Label1",
Margin = new Thickness(1,2,1,0)
//,Visibility = Visibility.Collapsed
});
panel.XChildren.Add(new TextBlock() {
Name = "label2",
Text = "Label2_____",
HorizontalAlignment = HorizontalAlignment.Right
});
TextBox textBox = new TextBox() {
MaxWidth = 10,
Margin = new Thickness(1),
HorizontalAlignment = HorizontalAlignment.Center,
Size = 15
};
Button button = new Button() {
Name = "button1",
Caption = "Button!",
Margin = new Thickness(1),
HorizontalAlignment = HorizontalAlignment.Center
};
button.OnClick += (sender, eventArgs) => {
Debug.WriteLine("Click");
MessageBox.Show( "Окно сообщения", "Внимание ! Тестовое сообщение", delegate( MessageBoxResult result ) { } );
Control label = panel.FindDirectChildByName("label1");
if (label.Visibility == Visibility.Visible) {
label.Visibility = Visibility.Collapsed;
} else if (label.Visibility == Visibility.Collapsed) {
label.Visibility = Visibility.Hidden;
} else {
label.Visibility = Visibility.Visible;
}
label.Invalidate();
};
ComboBox comboBox = new ComboBox( )
{
// Width = 14
//HorizontalAlignment = HorizontalAlignment.Stretch
};
comboBox.Items.Add( "Сделать одно" );
comboBox.Items.Add("Сделать второе");
comboBox.Items.Add("Ничего не делать");
ListBox listbox = new ListBox( );
listbox.Items.Add( "First item" );
listbox.Items.Add( "second item1!!!!!!1fff" );
listbox.HorizontalAlignment = HorizontalAlignment.Stretch;
//listbox.Width = 10;
panel.XChildren.Add(comboBox);
panel.XChildren.Add(button);
panel.XChildren.Add(textBox);
panel.XChildren.Add(listbox);
//application.Run(panel);
WindowsHost windowsHost = new WindowsHost()
{
Name = "WindowsHost"
};
Window window1 = new Window {
X = 5,
Y = 4,
//MinHeight = 100,
//MaxWidth = 30,
//Width = 10,
Height = 20,
Name = "Window1",
Title = "Window1",
Content = panel
};
GroupBox groupBox = new GroupBox( );
groupBox.Title = "Группа";
ScrollViewer scrollViewer = new ScrollViewer( );
ListBox listBox = new ListBox( );
for ( int i = 0; i < 30; i++ ) {
listBox.Items.Add(string.Format("Длинный элемент {0}", i));
}
// listBox.Items.Add( "Длинный элемент" );
// listBox.Items.Add("Длинный элемент 2");
// listBox.Items.Add("Длинный элемент 3");
// listBox.Items.Add("Длинный элемент 4");
// listBox.Items.Add("Длинный элемент 5");
// listBox.Items.Add("Длинный элемент 6");
// listBox.Items.Add("Длинный элемент 700");
listBox.HorizontalAlignment = HorizontalAlignment.Stretch;
listBox.VerticalAlignment = VerticalAlignment.Stretch;
scrollViewer.Content = listBox;
// scrollViewer.HorizontalAlignment = HorizontalAlignment.Stretch;
scrollViewer.VerticalAlignment = VerticalAlignment.Stretch;
scrollViewer.HorizontalScrollEnabled = true;
groupBox.Content = scrollViewer;
ComboBox combo = new ComboBox();
combo.ShownItemsCount = 10;
for ( int i = 0; i < 30; i++ ) {
combo.Items.Add(string.Format("Длинный элемент {0}", i));
}
// groupBox.Content = combo;
groupBox.HorizontalAlignment = HorizontalAlignment.Stretch;
windowsHost.Show(new Window() {
X = 30,
Y = 6,
//MinHeight = 10,
//MinWidth = 10,
Height = 14,
Name = "LongTitleWindow",
Title = "Очень длинное название окна",
Content = groupBox
});
windowsHost.Show(window1);
windowsHost.Show(createdFromXaml);
//textBox.SetFocus(); todo : научиться задавать фокусный элемент до добавления в визуальное дерево
//application.TerminalSizeChanged += ( sender, eventArgs ) => {
// application.CanvasSize = new Size(eventArgs.Width, eventArgs.Height);
// application.RootElementRect = new Rect(new Size(eventArgs.Width, eventArgs.Height));
// };
//windowsHost.Width = 80;
//windowsHost.Height = 20;
application.Run(windowsHost);//, new Size(80, 30), Rect.Empty);
}
}
}
}