diff -r 09d0bc6970b5 -r c724ac229181 src/FingersDance.Control.Menu/UserControlMenu.xaml.cs --- a/src/FingersDance.Control.Menu/UserControlMenu.xaml.cs Mon Sep 14 17:43:41 2009 +0200 +++ b/src/FingersDance.Control.Menu/UserControlMenu.xaml.cs Mon Sep 14 23:49:47 2009 +0200 @@ -7,6 +7,9 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; +using Microsoft.Surface; +using Microsoft.Surface.Presentation; +using System.Xml.Serialization; namespace FingersDance.Control.Menu { @@ -23,32 +26,97 @@ //Premet de deplacer les sous menus vers la droite pour avoir un effect tree view private void initChildSize() { - //Niveau 1 - PanelAnnotation.Width -= 0.10*this.Width; - PanelRecherche.Width -= 0.10 * this.Width; - //Niveau 2 - PanelChildChore.Width -= 0.10 * this.Width; - PanelChildCine.Width -= 0.10 * this.Width; - //Niveau 3 - PanelChild1AxeCam.Width -= 0.05 * this.Width; - PanelChild1MouvCam.Width -= 0.05 * this.Width; - + StreamReader reader = null; + reader = new StreamReader("../../Menu.iri"); + XmlSerializer serializer = new XmlSerializer(typeof(Menu)); + Menu temp = (Menu)serializer.Deserialize(reader); + foreach (Item elt in temp.Items) + try + { + LayoutRoot.Children.Add(CreateMenuItem(elt)); + } + catch (Exception) { } + reader.Close(); } - #region Events - //Annotation - private void ButtonAnnotation_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) - { - if (PanelAnnotation.Visibility == Visibility.Collapsed) - { - PanelAnnotation.Visibility = Visibility.Visible; - } - else - { - PanelAnnotation.Visibility = Visibility.Collapsed; - } - } + public StackPanel CreateMenuItem(Item item) + { + try + { + StackPanel MItem = new StackPanel(); + Microsoft.Surface.Presentation.Controls.SurfaceButton ItemButton = new Microsoft.Surface.Presentation.Controls.SurfaceButton(); + ItemButton.Content = item.Name; + if (item.Items.Count > 0) + { + ItemButton.ContactDown += ButtonMenu_ContactDown; + ItemButton.Click += ButtonMenu_ContactDown; + MItem.Children.Add(ItemButton); + StackPanel Temp = new StackPanel(); + Temp.Margin = new Thickness(15,0,0,0); + foreach (Item elt in item.Items) + try + { + Temp.Children.Add(CreateMenuItem(elt)); + } + catch (Exception) { } + Temp.Name = ItemButton.Content + "Panel"; + Temp.Visibility = Visibility.Collapsed; + MItem.Children.Add(Temp); + } + else + { + ItemButton.ContactDown += GenerateAction; + ItemButton.Click += GenerateAction; + MItem.Children.Add(ItemButton); + } + return MItem; + } + catch (Exception ex) + { + throw ex; + } + } + private void GenerateAction(Object sender, RoutedEventArgs Event) + { + try + { + ActionFactory.ActionGenerator AG = (new ActionFactory.ActionFactory()).GetGenerator(); + FingersDance.Actions.ActionBase action = AG.GetAction("Action" + ((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Content, null); + if (action != null) + { + //action.Execute(); + //this.debug.addToList(action.GetType().ToString()); + } + } + catch (Exception e) { } + } + + private void ButtonMenu_ContactDown(object sender, RoutedEventArgs e) + { + foreach (UIElement Child in ((Panel)((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Parent).Children) + try + { + if (((StackPanel)Child).Name.Equals(((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Content + "Panel")) + { + if (((StackPanel)Child).Visibility == Visibility.Collapsed) + { + ((StackPanel)Child).Visibility = Visibility.Visible; + } + else + { + ((StackPanel)Child).Visibility = Visibility.Collapsed; + } + return; + } + } + catch (Exception ex) { } + } + + #region Events + + /* + //Annotation private void ButtonAnnotation_Click(object sender, RoutedEventArgs e) { if (PanelAnnotation.Visibility == Visibility.Collapsed) @@ -180,6 +248,8 @@ PanelChild1AxeCam.Visibility = Visibility.Collapsed; } } + */ + #endregion