ui/wpf/UIcore/Controls.cs

changeset 135
b9dc9cdfa23a
parent 104
3efe0210e27e
equal deleted inserted replaced
134:69e8e0936858 135:b9dc9cdfa23a
8 8
9 namespace UI 9 namespace UI
10 { 10 {
11 public class Controls 11 public class Controls
12 { 12 {
13
14 public static Button Button(Container container, String label, RoutedEventHandler e) 13 public static Button Button(Container container, String label, RoutedEventHandler e)
15 {
16 return Application.GetInstance().Exec<Button>(() => Controls.CreateButton(container, label, e));
17 }
18
19 public static Label Label(Container container, String label, int alignment)
20 {
21 HorizontalAlignment a;
22 switch(alignment)
23 {
24 case 0: a = HorizontalAlignment.Left; break;
25 case 1: a = HorizontalAlignment.Right; break;
26 case 2: a = HorizontalAlignment.Center; break;
27 default: a = HorizontalAlignment.Left; break;
28 }
29 return Application.GetInstance().Exec<Label>(() => Controls.CreateLabel(container, label, a));
30 }
31
32 public static Label Space(Container container)
33 {
34 return Application.GetInstance().Exec<Label>(() => Controls.CreateLabel(container, null, HorizontalAlignment.Center));
35 }
36
37 public static Separator Separator(Container container)
38 {
39 return Application.GetInstance().Exec<Separator>(() => Controls.CreateSeparator(container));
40 }
41
42 public static Button CreateButton(Container container, String label, RoutedEventHandler e)
43 { 14 {
44 Button button = new Button(); 15 Button button = new Button();
45 button.Content = label; 16 button.Content = label;
46 container.Add(button, false); 17 container.Add(button, false);
47 18
48 button.Click += e; 19 button.Click += e;
49 20
50 return button; 21 return button;
51 } 22 }
52 23
53 public static Label CreateLabel(Container container, String str, HorizontalAlignment alignment) 24 public static Label Label(Container container, String str, int alignment)
54 { 25 {
26 HorizontalAlignment a;
27 switch (alignment)
28 {
29 case 0: a = HorizontalAlignment.Left; break;
30 case 1: a = HorizontalAlignment.Right; break;
31 case 2: a = HorizontalAlignment.Center; break;
32 default: a = HorizontalAlignment.Left; break;
33 }
34
55 Label label = new Label(); 35 Label label = new Label();
56 label.HorizontalAlignment = alignment; 36 label.HorizontalAlignment = a;
57 label.Content = str; 37 label.Content = str;
58 container.Add(label, false); 38 container.Add(label, false);
59 39
60 return label; 40 return label;
61 } 41 }
62 42
63 public static Separator CreateSeparator(Container container) 43 public static Label Space(Container container)
44 {
45 return Label(container, null, 2);
46 }
47
48 public static Separator Separator(Container container)
64 { 49 {
65 Separator separator = new Separator(); 50 Separator separator = new Separator();
66 container.Add(separator, false); 51 container.Add(separator, false);
67 return separator; 52 return separator;
68 } 53 }

mercurial