/// <summary> /// Parses the Window XML into a UI component. /// </summary> /// <param name="reader">XML reader object.</param> /// <returns>Window</returns> private static GlideWindow ParseWindow(XmlReader reader) { string name = reader.GetAttribute("Name"); int width = Convert.ToInt32(reader.GetAttribute("Width")); int height = Convert.ToInt32(reader.GetAttribute("Height")); if (Glide.FitToScreen && (width < Glide.LCD.Width || height < Glide.LCD.Height)) { width = Glide.LCD.Width; height = Glide.LCD.Height; } var backColor = GlideUtils.Convert.ToColor(reader.GetAttribute("BackColor")); var window = new GlideWindow() { Height = height, Width = width }; window.Background = new SolidColorBrush(backColor); //window.BackColor = backColor; window.Visibility = Visibility.Visible; return(window); }
/// <summary> /// Loads a Window from XML bytes. /// </summary> /// <param name="xmlBytes">XML bytes.</param> /// <returns>Window object.</returns> public static GlideWindow LoadWindow(byte[] xmlBytes) { ElementContainer tmp; XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.IgnoreComments = true; xmlReaderSettings.IgnoreProcessingInstructions = true; xmlReaderSettings.IgnoreWhitespace = true; MemoryStream stream = new MemoryStream(xmlBytes); XmlReader reader = XmlReader.Create(stream, xmlReaderSettings); if (!reader.ReadToDescendant("Glide")) { throw new ArgumentException("Glide not detected."); } stream.Seek(0, SeekOrigin.Begin); reader = XmlReader.Create(stream, xmlReaderSettings); if (!reader.ReadToDescendant("Window")) { throw new ArgumentException("XML does not contain a Window element."); } _window = ParseWindow(reader); UIElement component; _canvas = new Canvas(); while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Window")) { tmp = GetComponent(reader); component = tmp.Element; if (component != null) { _canvas.Children.Add(component); _window.AddControls(tmp.ElementName, tmp.Element); } else { throw new Exception(reader.Name + " is not a valid UI component."); } } _window.Child = _canvas; reader.Close(); _window.Invalidate(); return(_window); }