Example #1
0
 /// <summary>
 /// Read keyboard defintition from given path
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static KeyboardDefinition ReadKeyboard(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         throw new ArgumentOutOfRangeException(path);
     }
     var keyboard = new KeyboardDefinition();
     keyboard.Initialize(path);
     return keyboard;
 }
Example #2
0
 private void ChangeSubscription()
 {
     // if we have subscribed before - unsubscribe
     if (activeDefinition != null)
     {
         activeDefinition.KeyPressed -= new KeyPressed(activeDefinition_KeyPressed);
     }
     activeDefinition = KeyboardLayouts.Instance.SelectedLayout;
     if (activeDefinition != null)
     {
         activeDefinition.KeyPressed += new KeyPressed(activeDefinition_KeyPressed);
     }
 }
Example #3
0
 /// <summary>
 /// Read layouts data
 /// </summary>
 private void Read()
 {
     // open layouts definition file
     StreamResourceInfo stream =
         Application.GetResourceStream(new Uri(assemblyName + ";component/Layouts/Layouts.xml", UriKind.Relative));
     if (stream == null ||
         stream.Stream == null)
     {
         return;
     }
     string defaultLayout = string.Empty;
     // we use XML reader to reduce size of xap file
     using (stream.Stream)
     {
         using (XmlReader reader = XmlReader.Create(stream.Stream))
         {
             //reader.MoveToContent();
             // Parse the file and display each of the nodes.
             while (reader.Read())
             {
                 if (reader.NodeType == XmlNodeType.Element)
                 {
                     if (string.Compare(reader.Name, "Layout") == 0)
                     {
                         var path = reader.GetAttribute("path");
                         var name = reader.GetAttribute("name");
                         if (string.IsNullOrEmpty(path) ||
                             string.IsNullOrEmpty(name))
                         {
                             continue;
                         }
                         var keyboard =
                             KeyboardDefinition.ReadKeyboard(
                                 string.Format(assemblyName + ";component/Layouts/{0}", path));
                         allLayouts.Add(keyboard);
                         if (name == defaultLayout)
                         {
                             SelectedLayout = keyboard;
                         }
                     }
                     else if (string.Compare(reader.Name, "Layouts") == 0)
                     {
                         defaultLayout = reader.GetAttribute("default");
                     }
                 }
             }
         }
         allLayouts.Sort((item1, item2) => item1.Name.CompareTo(item2.Name));
         if (SelectedLayout == null &&
             allLayouts.Count > 0)
         {
             SelectedLayout = allLayouts[0];
         }
     }
 }