private static void RecursiveSerializeXML(XmlNode parentNode, UIControl parentControl) { foreach(XmlNode node in parentNode.ChildNodes) { UIControl control = new UIControl(); switch(node.Name) { case "TextBlock": case "TextBox": case "CheckBox": case "ComboBox": var textcontrol = new TextControl(); textcontrol.FontSize = StringToObjectConverter.StringTo<double>(((XmlElement)node).GetAttribute("FontSize")); textcontrol.FontStretch = (FontStretch)StringToObjectConverter.StringToProperty(((XmlElement)node).GetAttribute("FontStretch"), typeof(FontStretches), FontStretches.Normal); textcontrol.FontStyle = (FontStyle)StringToObjectConverter.StringToProperty(((XmlElement)node).GetAttribute("FontStyle"), typeof(FontStyles), FontStyles.Normal); textcontrol.FontWeight = (FontWeight)StringToObjectConverter.StringToProperty(((XmlElement)node).GetAttribute("FontWeight"), typeof(FontWeights), FontWeights.Normal); control = textcontrol; break; case "Image": var imagecontrol = new ImageControl(); imagecontrol.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(((XmlElement)node).GetAttribute("ImageSource"))); break; default: control = new UIControl(); break; } control.Background = StringToObjectConverter.StringToBrush(((XmlElement)node).GetAttribute("Background"), new System.Windows.Media.SolidColorBrush(new System.Windows.Media.Color() { A = (byte)0xFF, R = (byte)0xFF, G = (byte)0xFF, B = (byte)0xFF })); control.Component = StringToObjectConverter.StringToComponents(((XmlElement)node).Name); control.Foreground = StringToObjectConverter.StringToBrush(((XmlElement)node).GetAttribute("Foreground"), new System.Windows.Media.SolidColorBrush(new System.Windows.Media.Color() { A = (byte)0xFF, R = (byte)0x00, G = (byte)0x00, B = (byte)0x00 })); control.Height = StringToObjectConverter.StringTo<double>(((XmlElement)node).GetAttribute("Height")); control.HorizontalAlignment = (HorizontalAlignment?)StringToObjectConverter.StringToProperty(((XmlElement)node).GetAttribute("HorizontalAlignment"), typeof(HorizontalAlignment)); control.IsEnabled = StringToObjectConverter.StringTo<bool>(((XmlElement)node).GetAttribute("IsEnabled")); control.IsVisible = StringToObjectConverter.StringTo<bool>(((XmlElement)node).GetAttribute("IsVisible")); //control.Margin = control.Name = (((XmlElement)node).GetAttribute("Name")); control.Opacity = StringToObjectConverter.StringTo<double>(((XmlElement)node).GetAttribute("Opacity")); control.ToolTip = (((XmlElement)node).GetAttribute("ToolTip")); control.VerticalAlignment = (VerticalAlignment?)StringToObjectConverter.StringToProperty(((XmlElement)node).GetAttribute("VerticalAlignment"), typeof(VerticalAlignment)); control.Visibility = (Visibility?)StringToObjectConverter.StringToEnum(((XmlElement)node).GetAttribute("Visibility"), typeof(Visibility)); control.Width = StringToObjectConverter.StringTo<double>(((XmlElement)node).GetAttribute("Width")); parentControl.Children.Add(control); RecursiveSerializeXML(node, control); } }
private static void SerializeXML(Plugin plugin, string dir) { if(!FileController.Exists(dir + "\\ui.xml")) { return; } try { XmlDocument document = new XmlDocument(); document.Load(dir + "\\ui.xml"); XmlNode root = document.DocumentElement; XmlNode node = root.ChildNodes[0]; UIControl control = new UIControl(); control.Component = (GuiComponents)Enum.Parse(typeof(GuiComponents), ((XmlElement)node).Name); //再帰的処理 RecursiveSerializeXML(node, control); plugin.Controls.Add(control); } catch (Exception e) { plugin.Logger.Error("Load failed.", e); } }