/// <summary> /// Generates the xaml that is to be displayed. /// </summary> /// <param name="data">The data the xaml is constructed from.</param> /// <returns>The xaml representation of the input.</returns> public string GenerateXaml(TokenTree data) { if (_sb.Generated.Length <= 0) { TokenTree parameters = new TokenTree(data.GetChildren("Parameters")); DataConverter.Parameters = parameters; foreach (TokenTree child in parameters.Children) { string name = child.Name; TokenTree defaults = parameters.FindFirst("Defaults." + name); if (defaults != null) foreach (TokenTree item in child.Children) item.AddMissing(defaults); } TokenTreeList fields = data.GetAll("Fields"); TokenTreeList styles = data.GetAll("Styles"); _sb.Append( "<Border HorizontalAlignment=\"Stretch\" VerticalAlignment=\"Stretch\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">") .AppendLine(); if (styles != null && styles.Count > 0) AddStyles(styles, parameters); foreach (TokenTree field in fields.SelectMany(child => child.Children)) _sb.AddElement(field, 1, parameters); _sb.Append("</Border>").AppendLine(); } return _sb.Generated; }
/// <summary> /// Generates the html that is to be displayed. /// </summary> /// <param name="data">The data the html is constructed from.</param> /// <param name="selected">The selected item for displaying.</param> /// <param name="dataName">The name of the data structure that contains item information.</param> /// <param name="keys">List of selectable items.</param> /// <returns>The html representation of the input.</returns> public string GenerateHtml(TokenTree data, TokenTree selected, string dataName, List<string> keys) { TokenTree parameters = new TokenTree(data.GetChildren("Parameters")); foreach (TokenTree child in parameters.Children) { string name = child.Name; TokenTree defaults = parameters.FindFirst("Defaults." + name); if (defaults != null) foreach (TokenTree item in child.Children) item.AddMissing(defaults); } _sb.Clear(); TokenTree values = selected.Clone(); TokenTree defaultValues = parameters.FindFirst("Defaults." + dataName); if (defaultValues != null) values.AddMissing(defaultValues); values.SetParameters(parameters); TokenTreeList fields = data.GetAll("Fields"); TokenTreeList styles = data.GetAll("Styles").FindMatches("Style", true); AddStyles(styles, parameters); foreach (TokenTree field in fields.SelectMany(child => child.Children).Where(x => x.Name == "Field")) _sb.AddElement(field, 0, parameters, values, keys); return _sb.Generated; }
public string GenerateXaml(TokenTree data) { TokenTree parameters = new TokenTree(data.GetChildren("Parameters")); DataConverter.Parameters = parameters; foreach (TokenTree child in parameters.Children) { string name = child.Name; TokenTree defaults = DataConverter.Parameters.FindFirst("Defaults." + name); if (defaults != null) foreach (TokenTree item in child.Children) item.AddMissing(defaults); } TokenTreeList fields = data.Children.FindMatches("Fields"); foreach (TokenTree field in fields.SelectMany(child => child.Children)) Field.AddChild(field, 0, parameters, _sb, _offset, _endOfLine); return _sb.ToString(); }