/// <summary> /// Loads the contents of the specified filename in the given <see cref="Desktop"/> instance. /// </summary> /// <param name="desktop">The desktop.</param> /// <param name="filename">The filename.</param> public static void Load(Desktop desktop, string filename) { XElement root = LoadFromFile(filename); if (root == null) { return; } // Widget Deserialization IEnumerable <XElement> widgetsXML = root.Elements("WidgetElements").Elements("WidgetElement"); foreach (XElement widgetXML in widgetsXML) { Guid id = new Guid(widgetXML.Element("Id").Value); WidgetElement item = DeserializeWidget(widgetXML, id, 0, 0); desktop.AddElement(item, item.GetPosition()); } // Shortcut Deserialization IEnumerable <XElement> shortcutsXML = root.Elements("ShortcutElements").Elements("ShortcutElement"); int ti = 0; foreach (XElement shortcutXML in shortcutsXML) { Guid id = new Guid(shortcutXML.Element("Id").Value); ShortcutElement item = DeserializeShortcut(shortcutXML, id, 0, 0); item.TabIndex = ++ti; desktop.AddElement(item, item.GetPosition()); } }
/// <summary> /// Creates a new shortcut with the given title and target /// </summary> /// <param name="title"></param> /// <param name="target"></param> public void CreateShortcut <T>(string title, string target, Point point) where T : IShortcutViewModel, new() { T shortcut = new T { Title = title, Target = target }; ShortcutElement element = new ShortcutElement { DataContext = shortcut }; this.Show(element, point); }
private static ShortcutElement DeserializeShortcut(XElement itemXML, Guid id, double offsetX, double offsetY) { ShortcutElement item = new ShortcutElement { DataContext = XamlReader.Load(XmlReader.Create(new StringReader(itemXML.Element("DataContext").Value))), Width = Double.Parse(itemXML.Element("Width").Value, CultureInfo.InvariantCulture), Height = Double.Parse(itemXML.Element("Height").Value, CultureInfo.InvariantCulture) }; item.StartupLocation = StartupPosition.Manual; item.Move(Double.Parse(itemXML.Element("Left").Value, CultureInfo.InvariantCulture) + offsetX, Double.Parse(itemXML.Element("Top").Value, CultureInfo.InvariantCulture) + offsetY); item.SetZIndex(Int32.Parse(itemXML.Element("zIndex").Value)); return(item); }