author | cavaliet |
Thu, 12 Nov 2009 16:15:19 +0100 | |
changeset 192 | 11083c390ce4 |
parent 44 | 9c6ea1f246da |
permissions | -rw-r--r-- |
19 | 1 |
using System; |
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Windows; |
|
6 |
using System.Windows.Controls; |
|
7 |
using System.Windows.Data; |
|
8 |
using System.Windows.Documents; |
|
9 |
using System.Windows.Input; |
|
10 |
using System.Windows.Media; |
|
11 |
using System.Windows.Media.Imaging; |
|
12 |
using System.Windows.Shapes; |
|
13 |
using System.Windows.Threading; |
|
14 |
using Microsoft.Surface; |
|
15 |
using Microsoft.Surface.Presentation; |
|
16 |
using Microsoft.Surface.Presentation.Controls; |
|
17 |
using System.IO; |
|
18 |
using System.Xml.Serialization; |
|
19 |
||
20 |
namespace TestMenu |
|
21 |
{ |
|
22 |
/// <summary> |
|
23 |
/// Interaction logic for SurfaceWindow1.xaml |
|
24 |
/// </summary> |
|
25 |
public partial class SurfaceWindow1 : SurfaceWindow |
|
26 |
{ |
|
27 |
/// <summary> |
|
28 |
/// Default constructor. |
|
29 |
/// </summary> |
|
27 | 30 |
|
38 | 31 |
FingersDance.ActionFactory.ActionFactory _Factory = new FingersDance.ActionFactory.ActionFactory(); |
39 | 32 |
//this.Debug |
33 |
//FingersDance.Debug.UserControlDebug Debug = new FingersDance.Debug.SurfaceWindow1(); |
|
27 | 34 |
|
19 | 35 |
public SurfaceWindow1() |
36 |
{ |
|
37 |
InitializeComponent(); |
|
38 |
||
39 |
StreamReader reader = null; |
|
24 | 40 |
reader = new StreamReader("../../test.xml"); |
19 | 41 |
XmlSerializer serializer = new XmlSerializer(typeof(Menu)); |
42 |
Menu temp = (Menu)serializer.Deserialize(reader); |
|
43 |
foreach (Item elt in temp.Items) |
|
29 | 44 |
try |
45 |
{ |
|
46 |
MyMenu.Items.Add(CreateMenuItem(elt)); |
|
47 |
} |
|
48 |
catch (Exception) { } |
|
19 | 49 |
reader.Close(); |
50 |
||
51 |
// Add handlers for Application activation events |
|
52 |
AddActivationHandlers(); |
|
53 |
} |
|
54 |
||
55 |
public SurfaceMenuItem CreateMenuItem(Item item) |
|
56 |
{ |
|
29 | 57 |
try |
23 | 58 |
{ |
29 | 59 |
SurfaceMenuItem MItem = new SurfaceMenuItem(); |
60 |
MItem.Header = item.Name; |
|
61 |
MItem.Visibility = Visibility.Visible; |
|
62 |
if (!item.Action.Equals("")) |
|
63 |
{ |
|
64 |
MItem.ContactDown += GenerateAction; |
|
65 |
MItem.Click += GenerateAction; |
|
66 |
} |
|
67 |
foreach (Item elt in item.Items) |
|
68 |
try |
|
69 |
{ |
|
70 |
MItem.Items.Add(CreateMenuItem(elt)); |
|
71 |
} |
|
72 |
catch (Exception) { } |
|
73 |
return MItem; |
|
23 | 74 |
} |
29 | 75 |
catch (Exception ex) |
76 |
{ |
|
77 |
throw ex; |
|
78 |
} |
|
19 | 79 |
} |
80 |
||
23 | 81 |
private void GenerateAction(Object sender, EventArgs Event) |
82 |
{ |
|
29 | 83 |
try |
84 |
{ |
|
44
9c6ea1f246da
Correction tu TestMenu
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
39
diff
changeset
|
85 |
FingersDance.Actions.ActionBase action = _Factory.GetAction("Action" + ((SurfaceMenuItem)sender).Header, "Tu as cliqué sur " + ((SurfaceMenuItem)sender).Header); |
29 | 86 |
if (action != null) |
39 | 87 |
{ |
88 |
//action.Execute(); |
|
89 |
this.debug.addToList(action.GetType().ToString()); |
|
90 |
} |
|
29 | 91 |
} |
44
9c6ea1f246da
Correction tu TestMenu
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
39
diff
changeset
|
92 |
catch (Exception e) { } |
23 | 93 |
} |
94 |
||
19 | 95 |
/// <summary> |
96 |
/// Occurs when the window is about to close. |
|
97 |
/// </summary> |
|
98 |
/// <param name="e"></param> |
|
99 |
protected override void OnClosed(EventArgs e) |
|
100 |
{ |
|
101 |
base.OnClosed(e); |
|
102 |
||
103 |
// Remove handlers for Application activation events |
|
104 |
RemoveActivationHandlers(); |
|
105 |
} |
|
106 |
||
107 |
/// <summary> |
|
108 |
/// Adds handlers for Application activation events. |
|
109 |
/// </summary> |
|
110 |
private void AddActivationHandlers() |
|
111 |
{ |
|
112 |
// Subscribe to surface application activation events |
|
113 |
ApplicationLauncher.ApplicationActivated += OnApplicationActivated; |
|
114 |
ApplicationLauncher.ApplicationPreviewed += OnApplicationPreviewed; |
|
115 |
ApplicationLauncher.ApplicationDeactivated += OnApplicationDeactivated; |
|
116 |
} |
|
117 |
||
118 |
/// <summary> |
|
119 |
/// Removes handlers for Application activation events. |
|
120 |
/// </summary> |
|
121 |
private void RemoveActivationHandlers() |
|
122 |
{ |
|
123 |
// Unsubscribe from surface application activation events |
|
124 |
ApplicationLauncher.ApplicationActivated -= OnApplicationActivated; |
|
125 |
ApplicationLauncher.ApplicationPreviewed -= OnApplicationPreviewed; |
|
126 |
ApplicationLauncher.ApplicationDeactivated -= OnApplicationDeactivated; |
|
127 |
} |
|
128 |
||
129 |
/// <summary> |
|
130 |
/// This is called when application has been activated. |
|
131 |
/// </summary> |
|
132 |
/// <param name="sender"></param> |
|
133 |
/// <param name="e"></param> |
|
134 |
private void OnApplicationActivated(object sender, EventArgs e) |
|
135 |
{ |
|
136 |
//TODO: enable audio, animations here |
|
137 |
} |
|
138 |
||
139 |
/// <summary> |
|
140 |
/// This is called when application is in preview mode. |
|
141 |
/// </summary> |
|
142 |
/// <param name="sender"></param> |
|
143 |
/// <param name="e"></param> |
|
144 |
private void OnApplicationPreviewed(object sender, EventArgs e) |
|
145 |
{ |
|
146 |
//TODO: Disable audio here if it is enabled |
|
147 |
||
148 |
//TODO: optionally enable animations here |
|
149 |
} |
|
150 |
||
151 |
/// <summary> |
|
152 |
/// This is called when application has been deactivated. |
|
153 |
/// </summary> |
|
154 |
/// <param name="sender"></param> |
|
155 |
/// <param name="e"></param> |
|
156 |
private void OnApplicationDeactivated(object sender, EventArgs e) |
|
157 |
{ |
|
158 |
//TODO: disable audio, animations here |
|
159 |
} |
|
160 |
} |
|
161 |
} |