void ParseElementDescr(elementDescr parentDescr) { var xmlLinkedNode = parentDescr.XmlElement as XmlLinkedNode; if (xmlLinkedNode != null) { xmlLinkedNode.ForEach(nodes => { var element = nodes as XmlElement; var text = nodes as XmlText; if (element != null) { elementDescr elDescr = new elementDescr() { Name = element.Name, XmlElement = element }; ParseElementDescr(elDescr); parentDescr.Childs.Add(elDescr); } if (text != null) { parentDescr.Value = text.Value; } }); } else { int i = 0; } }
elementDescr ParseXmlItem(ItemList.ElementItem elemItem) { var element = elemItem.any; elementDescr elem = new elementDescr() { Name = element.LocalName, XmlElement = element }; ParseElementDescr(elem); return(elem); }
FrameworkElement GetXmlElementView(elementDescr element, string parentName) { FrameworkElement felement = null; if (element.HasChilds) { Expander grbox = new Expander(); //grbox.Padding = new Thickness(20, 0, 0, 0); //if (parentName != "__Top") { // //grbox.Margin = new Thickness(10, 0, 0, 0); //} grbox.Header = element.Name; StackPanel spanel = new StackPanel(); spanel.Orientation = Orientation.Vertical; element.Childs.ForEach(child => { spanel.Children.Add(GetXmlElementView(child, element.Name)); }); spanel.Margin = new Thickness(20, 0, 0, 0); grbox.Content = spanel; felement = grbox; } else { StackPanel spanel = new StackPanel(); spanel.Orientation = Orientation.Horizontal; TextBlock tblock = new TextBlock(); tblock.Margin = new Thickness(3); tblock.Text = element.Name; tblock.MinWidth = 150; tblock.Foreground = Brushes.DarkGray; tblock.FontWeight = FontWeights.Bold; tblock.VerticalAlignment = System.Windows.VerticalAlignment.Center; spanel.Children.Add(tblock); spanel.Children.Add(GetValueEditor(element)); spanel.Margin = new Thickness(20, 0, 0, 0); felement = spanel; } return(felement); }
void PrepareChilds(elementDescr xmlElement, odm.ui.controls.SchemaParser.xsdElement schemaElement) { if (xmlElement.HasChilds) { xmlElement.Childs.ForEach(chld => { var icomplex = schemaElement.Type as odm.ui.controls.SchemaParser.IComplexType; var isimple = schemaElement.Type as odm.ui.controls.SchemaParser.ISimpleType; var ipure = schemaElement.Type as odm.ui.controls.SchemaParser.IPureType; if (icomplex != null) { var content = icomplex.Content.FirstOrDefault(schemel => schemel.Name == chld.Name); if (content == null) { return; } if (content.Type.ContentType == SchemaParser.ContentTypes.pureType) { chld.QName = content.Type.QName; } else { PrepareChilds(chld, content); } } else if (isimple != null) { chld.Defaults = isimple.SimpleValues; } else if (ipure != null) { int i = 0; } }); } else { var isimple = schemaElement.Type as odm.ui.controls.SchemaParser.ISimpleType; if (isimple != null) { xmlElement.QName = isimple.QName; xmlElement.Defaults = isimple.SimpleValues; } } }
public void RemoveChild(elementDescr child) { childs.Remove(child); NotifyPropertyChanged("Childs"); }
public void AddChild(elementDescr child) { childs.Add(child); NotifyPropertyChanged("Childs"); }
FrameworkElement GetValueEditor(elementDescr element) { FrameworkElement felem = null; switch (element.QName.Name) { case "int": IntegerUpDown numUp = new IntegerUpDown(); numUp.Margin = new Thickness(3); numUp.Increment = 1; numUp.VerticalAlignment = VerticalAlignment.Center; numUp.MinWidth = 50; numUp.CreateBinding(IntegerUpDown.ValueProperty, element, x => { int val = 0; int.TryParse(element.Value, out val); return(val); }, (o, v) => { o.Value = v.ToString(); }); felem = numUp; break; case "float": DoubleUpDown doubleUp = new DoubleUpDown(); doubleUp.CultureInfo = System.Globalization.CultureInfo.InvariantCulture; doubleUp.Margin = new Thickness(3); doubleUp.Increment = 0.01f; doubleUp.FormatString = "F3"; doubleUp.VerticalAlignment = VerticalAlignment.Center; doubleUp.MinWidth = 50; doubleUp.CreateBinding(DoubleUpDown.ValueProperty, element, x => { float val = 0; //float.TryParse(element.Value, out val); try { val = XmlConvert.ToSingle(element.Value); }catch (Exception err) { dbg.Error(err); } return(val); }, (o, v) => { o.Value = XmlConvert.ToString(v); }); felem = doubleUp; break; case "boolean": CheckBox chBox = new CheckBox(); chBox.Margin = new Thickness(3); chBox.CreateBinding(CheckBox.IsCheckedProperty, element, x => { bool val = false; bool.TryParse(element.Value, out val); return(val); }, (o, v) => { o.Value = v.ToString(); }); felem = chBox; break; default: TextBox tbox = new TextBox(); tbox.Margin = new Thickness(3); tbox.CreateBinding(TextBox.TextProperty, element, x => x.Value, (o, v) => { o.Value = v; }); tbox.MinWidth = 50; tbox.VerticalAlignment = System.Windows.VerticalAlignment.Center; felem = tbox; break; } return(felem); }
public void AddChild(elementDescr child) { childs.Add(child); NotifyPropertyChanged("Childs"); }
public void RemoveChild(elementDescr child) { childs.Remove(child); NotifyPropertyChanged("Childs"); }
void ParseElementDescr(elementDescr parentDescr) { var xmlLinkedNode = parentDescr.XmlElement as XmlLinkedNode; if (xmlLinkedNode != null) { xmlLinkedNode.ForEach(nodes => { var element = nodes as XmlElement; var text = nodes as XmlText; if (element != null) { elementDescr elDescr = new elementDescr() { Name = element.Name, XmlElement = element }; ParseElementDescr(elDescr); parentDescr.Childs.Add(elDescr); } if (text != null) { parentDescr.Value = text.Value; } }); } else { int i = 0; } }
elementDescr ParseXmlItem(ItemList.ElementItem elemItem) { var element = elemItem.any; elementDescr elem = new elementDescr() { Name = element.LocalName, XmlElement = element }; ParseElementDescr(elem); return elem; }
void PrepareChilds(elementDescr xmlElement, odm.ui.controls.SchemaParser.xsdElement schemaElement) { if (xmlElement.HasChilds) { xmlElement.Childs.ForEach(chld => { var icomplex = schemaElement.Type as odm.ui.controls.SchemaParser.IComplexType; var isimple = schemaElement.Type as odm.ui.controls.SchemaParser.ISimpleType; var ipure = schemaElement.Type as odm.ui.controls.SchemaParser.IPureType; if(icomplex != null){ var content = icomplex.Content.FirstOrDefault(schemel => schemel.Name == chld.Name); if (content == null) return; if (content.Type.ContentType == SchemaParser.ContentTypes.pureType) { chld.QName = content.Type.QName; } else { PrepareChilds(chld, content); } } else if (isimple != null) { chld.Defaults = isimple.SimpleValues; } else if (ipure != null) { int i = 0; } }); } else { var isimple = schemaElement.Type as odm.ui.controls.SchemaParser.ISimpleType; if (isimple != null) { xmlElement.QName = isimple.QName; xmlElement.Defaults = isimple.SimpleValues; } } }
FrameworkElement GetValueEditor(elementDescr element) { FrameworkElement felem = null; switch (element.QName.Name) { case "int": IntegerUpDown numUp = new IntegerUpDown(); numUp.Margin = new Thickness(3); numUp.Increment = 1; numUp.VerticalAlignment = VerticalAlignment.Center; numUp.MinWidth = 50; numUp.CreateBinding(IntegerUpDown.ValueProperty, element, x => { int val = 0; int.TryParse(element.Value, out val); return val; }, (o, v) => { o.Value = v.ToString(); }); felem = numUp; break; case "float": DoubleUpDown doubleUp = new DoubleUpDown(); doubleUp.CultureInfo = System.Globalization.CultureInfo.InvariantCulture; doubleUp.Margin = new Thickness(3); doubleUp.Increment = 0.01f; doubleUp.FormatString = "F3"; doubleUp.VerticalAlignment = VerticalAlignment.Center; doubleUp.MinWidth = 50; doubleUp.CreateBinding(DoubleUpDown.ValueProperty, element, x => { float val = 0; //float.TryParse(element.Value, out val); try { val = XmlConvert.ToSingle(element.Value); }catch(Exception err){ dbg.Error(err); } return val; }, (o, v) => { o.Value = XmlConvert.ToString(v); }); felem = doubleUp; break; case "boolean": CheckBox chBox = new CheckBox(); chBox.Margin = new Thickness(3); chBox.CreateBinding(CheckBox.IsCheckedProperty, element, x => { bool val = false; bool.TryParse(element.Value, out val); return val; }, (o, v) => { o.Value = v.ToString(); }); felem = chBox; break; default: TextBox tbox = new TextBox(); tbox.Margin = new Thickness(3); tbox.CreateBinding(TextBox.TextProperty, element, x => x.Value, (o, v) => { o.Value = v; }); tbox.MinWidth = 50; tbox.VerticalAlignment = System.Windows.VerticalAlignment.Center; felem = tbox; break; } return felem; }
FrameworkElement GetXmlElementView(elementDescr element, string parentName) { FrameworkElement felement = null; if (element.HasChilds) { Expander grbox = new Expander(); //grbox.Padding = new Thickness(20, 0, 0, 0); //if (parentName != "__Top") { // //grbox.Margin = new Thickness(10, 0, 0, 0); //} grbox.Header = element.Name; StackPanel spanel = new StackPanel(); spanel.Orientation = Orientation.Vertical; element.Childs.ForEach(child => { spanel.Children.Add(GetXmlElementView(child, element.Name)); }); spanel.Margin = new Thickness(20, 0, 0, 0); grbox.Content = spanel; felement = grbox; } else{ StackPanel spanel = new StackPanel(); spanel.Orientation = Orientation.Horizontal; TextBlock tblock = new TextBlock(); tblock.Margin = new Thickness(3); tblock.Text = element.Name; tblock.MinWidth = 150; tblock.Foreground = Brushes.DarkGray; tblock.FontWeight = FontWeights.Bold; tblock.VerticalAlignment = System.Windows.VerticalAlignment.Center; spanel.Children.Add(tblock); spanel.Children.Add(GetValueEditor(element)); spanel.Margin = new Thickness(20, 0, 0, 0); felement = spanel; } return felement; }