/// <summary>
 /// initialize layout from xml file
 /// </summary>
 /// <param name="path"></param>
 private void Initialize(string path)
 {
     Rows.Clear();
     bool allKeysDefinedInXml = false;
     StreamResourceInfo stream = Application.GetResourceStream(new Uri(path, UriKind.Relative));
     if (stream == null ||
         stream.Stream == null)
     {
         throw new KeyboardException(string.Format("Failed to find layout file: {0}", path));
     }
     CultureInfo keyboardCulture = null;
     // we use XML reader to reduce size of xap file
     using (stream.Stream)
     {
         using (XmlReader reader = XmlReader.Create(stream.Stream))
         {
             // Parse the file and display each of the nodes.
             while (reader.Read())
             {
                 if (reader.NodeType == XmlNodeType.Element)
                 {
                     if (string.Compare(reader.Name, "Rows") == 0)
                     {
                         Rows.ReadXml(reader);
                     }
                     else if (string.Compare(reader.Name, "Keyboard") == 0)
                     {
                         var language = reader.GetAttribute("language");
                         var culture = reader.GetAttribute("culture");
                         bool.TryParse(reader.GetAttribute("all"), out allKeysDefinedInXml); 
                         
                         if (!string.IsNullOrEmpty(language))
                         {
                             this.Name = language;
                         }
                         if (!string.IsNullOrEmpty(culture))
                         {
                             keyboardCulture = new CultureInfo(culture);
                         }
                     }
                 }
             }
         }
         if (!allKeysDefinedInXml) // if all keys are defined in xml we do not need hardcoded insertion
         {
             AddSpecialKeys();
         }
         status = new KeyboardStatus(keyboardCulture);
         SubscribeToKeyEvents();
     }
 }
Exemple #2
0
 /// <summary>
 /// Register global keyboard status
 /// </summary>
 /// <param name="mainStatus"></param>
 internal virtual void RegisterStatusHolder(KeyboardStatus mainStatus)
 {
     this.status = mainStatus;
     status.PropertyChanged += new PropertyChangedEventHandler(status_PropertyChanged);
     UpdateStatus();
 }