src/FingersDance.Control.Menu/UserControlMenu.xaml.cs
changeset 54 c724ac229181
parent 10 e8bfe1102e03
child 59 1043e7c13ffc
equal deleted inserted replaced
53:09d0bc6970b5 54:c724ac229181
     5 using System.Windows.Controls;
     5 using System.Windows.Controls;
     6 using System.Windows.Data;
     6 using System.Windows.Data;
     7 using System.Windows.Media;
     7 using System.Windows.Media;
     8 using System.Windows.Media.Animation;
     8 using System.Windows.Media.Animation;
     9 using System.Windows.Navigation;
     9 using System.Windows.Navigation;
       
    10 using Microsoft.Surface;
       
    11 using Microsoft.Surface.Presentation;
       
    12 using System.Xml.Serialization;
    10 
    13 
    11 namespace FingersDance.Control.Menu
    14 namespace FingersDance.Control.Menu
    12 {
    15 {
    13 	public partial class UserControlMenu
    16 	public partial class UserControlMenu
    14 	{
    17 	{
    21 		}
    24 		}
    22 
    25 
    23         //Premet de deplacer les sous menus vers la droite pour avoir un effect tree view
    26         //Premet de deplacer les sous menus vers la droite pour avoir un effect tree view
    24          private void initChildSize()
    27          private void initChildSize()
    25         {
    28         {
    26              //Niveau 1
    29             StreamReader reader = null;
    27             PanelAnnotation.Width -= 0.10*this.Width;
    30             reader = new StreamReader("../../Menu.iri");
    28             PanelRecherche.Width -= 0.10 * this.Width;
    31             XmlSerializer serializer = new XmlSerializer(typeof(Menu));
    29              //Niveau 2
    32             Menu temp = (Menu)serializer.Deserialize(reader);
    30             PanelChildChore.Width -= 0.10 * this.Width;
    33             foreach (Item elt in temp.Items)
    31             PanelChildCine.Width -= 0.10 * this.Width;
    34                 try
    32              //Niveau 3
    35                 {
    33             PanelChild1AxeCam.Width -= 0.05 * this.Width;
    36                     LayoutRoot.Children.Add(CreateMenuItem(elt));
    34             PanelChild1MouvCam.Width -= 0.05 * this.Width;
    37                 }
    35 
    38                 catch (Exception) { }
    36         }
    39             reader.Close();
    37 
    40         }
    38          #region Events
    41 
    39          //Annotation
    42          public StackPanel CreateMenuItem(Item item)
    40         private void ButtonAnnotation_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
    43          {
    41         {
    44              try
    42             if (PanelAnnotation.Visibility == Visibility.Collapsed)
    45              {
    43             {
    46                  StackPanel MItem = new StackPanel();
    44                 PanelAnnotation.Visibility = Visibility.Visible;
    47                  Microsoft.Surface.Presentation.Controls.SurfaceButton ItemButton = new Microsoft.Surface.Presentation.Controls.SurfaceButton();
    45             }
    48                  ItemButton.Content = item.Name;
    46             else
    49                  if (item.Items.Count > 0)
    47             {
    50                  {
    48                 PanelAnnotation.Visibility = Visibility.Collapsed;
    51                      ItemButton.ContactDown += ButtonMenu_ContactDown;
    49             }
    52                      ItemButton.Click += ButtonMenu_ContactDown;
    50         }
    53                      MItem.Children.Add(ItemButton);
    51 
    54                      StackPanel Temp = new StackPanel();
       
    55                      Temp.Margin = new Thickness(15,0,0,0);
       
    56                      foreach (Item elt in item.Items)
       
    57                          try
       
    58                          {
       
    59                              Temp.Children.Add(CreateMenuItem(elt));
       
    60                          }
       
    61                          catch (Exception) { }
       
    62                      Temp.Name = ItemButton.Content + "Panel";
       
    63                      Temp.Visibility = Visibility.Collapsed;
       
    64                      MItem.Children.Add(Temp);
       
    65                  }
       
    66                  else
       
    67                  {
       
    68                      ItemButton.ContactDown += GenerateAction;
       
    69                      ItemButton.Click += GenerateAction;
       
    70                      MItem.Children.Add(ItemButton);
       
    71                  }
       
    72                  return MItem;
       
    73              }
       
    74              catch (Exception ex)
       
    75              {
       
    76                  throw ex;
       
    77              }
       
    78          }
       
    79 
       
    80          private void GenerateAction(Object sender, RoutedEventArgs Event)
       
    81          {
       
    82              try
       
    83              {
       
    84                  ActionFactory.ActionGenerator AG = (new ActionFactory.ActionFactory()).GetGenerator();
       
    85                  FingersDance.Actions.ActionBase action = AG.GetAction("Action" + ((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Content, null);
       
    86                  if (action != null)
       
    87                  {
       
    88                      //action.Execute();
       
    89                      //this.debug.addToList(action.GetType().ToString());
       
    90                  }
       
    91              }
       
    92              catch (Exception e) { }
       
    93          }
       
    94 
       
    95          private void ButtonMenu_ContactDown(object sender, RoutedEventArgs e)
       
    96          {
       
    97              foreach (UIElement Child in ((Panel)((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Parent).Children)
       
    98                  try
       
    99                  {
       
   100                      if (((StackPanel)Child).Name.Equals(((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Content + "Panel"))
       
   101                      {
       
   102                          if (((StackPanel)Child).Visibility == Visibility.Collapsed)
       
   103                          {
       
   104                              ((StackPanel)Child).Visibility = Visibility.Visible;
       
   105                          }
       
   106                          else
       
   107                          {
       
   108                              ((StackPanel)Child).Visibility = Visibility.Collapsed;
       
   109                          }
       
   110                          return;
       
   111                      }
       
   112                  }
       
   113                  catch (Exception ex) { }
       
   114          }
       
   115 
       
   116         #region Events
       
   117 
       
   118      /*    
       
   119         //Annotation
    52         private void ButtonAnnotation_Click(object sender, RoutedEventArgs e)
   120         private void ButtonAnnotation_Click(object sender, RoutedEventArgs e)
    53         {
   121         {
    54             if (PanelAnnotation.Visibility == Visibility.Collapsed)
   122             if (PanelAnnotation.Visibility == Visibility.Collapsed)
    55             {
   123             {
    56                 PanelAnnotation.Visibility = Visibility.Visible;
   124                 PanelAnnotation.Visibility = Visibility.Visible;
   178             else
   246             else
   179             {
   247             {
   180                 PanelChild1AxeCam.Visibility = Visibility.Collapsed;
   248                 PanelChild1AxeCam.Visibility = Visibility.Collapsed;
   181             }
   249             }
   182         }
   250         }
       
   251         */
       
   252         
   183         #endregion
   253         #endregion
   184 
   254 
   185     
   255     
   186     }
   256     }
   187 }
   257 }