public static FrameworkElement Render(TypedElement element, RenderContext context) { TextInput input = (TextInput)element; if (context.Config.SupportsInteractivity) { var textBox = new WatermarkTextBox() { Text = input.Value }; if (input.IsMultiline == true) { textBox.AcceptsReturn = true; textBox.TextWrapping = TextWrapping.Wrap; textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; } if (input.MaxLength > 0) { textBox.MaxLength = input.MaxLength; } textBox.Watermark = input.Placeholder; textBox.Style = context.GetStyle($"Adaptive.Input.Text.{input.Style}"); textBox.DataContext = input; context.InputBindings.Add(input.Id, () => textBox.Text); return(textBox); } else { var textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; return(context.Render(textBlock)); } }
public static FrameworkElement Render(TypedElement element, RenderContext context) { DateInput input = (DateInput)element; if (context.Config.SupportsInteractivity) { var datePicker = new DatePicker(); datePicker.ToolTip = input.Placeholder; DateTime value; if (DateTime.TryParse(input.Value, out value)) { datePicker.SelectedDate = value; } DateTime minValue; if (DateTime.TryParse(input.Min, out minValue)) { datePicker.DisplayDateStart = minValue; } DateTime maxValue; if (DateTime.TryParse(input.Max, out maxValue)) { datePicker.DisplayDateEnd = maxValue; } datePicker.Style = context.GetStyle("Adaptive.Input.Date"); datePicker.DataContext = input; context.InputBindings.Add(input.Id, () => datePicker.Text); return(datePicker); } else { var textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; return(context.Render(textBlock)); } }
protected static HtmlTag TimeInputRender(TypedElement element, RenderContext context) { TimeInput input = (TimeInput)element; var uiTimeInput = new HtmlTag("input") .Attr("type", "time") .Attr("name", input.Id) .AddClass("ac-input") .AddClass("ac-timeInput") .Style("width", "100%"); if (!string.IsNullOrEmpty(input.Value)) { uiTimeInput.Attr("value", input.Value); } if (!string.IsNullOrEmpty(input.Min)) { uiTimeInput.Attr("min", input.Min); } if (!string.IsNullOrEmpty(input.Max)) { uiTimeInput.Attr("max", input.Max); } return(uiTimeInput); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { DateInput input = (DateInput)element; if (context.Config.SupportsInteractivity) { var textBox = new TextBox() { Text = input.Value }; textBox.SetPlaceholder(input.Placeholder); textBox.Style = context.GetStyle($"Adaptive.Input.Text.Date"); textBox.SetContext(input); context.InputBindings.Add(input.Id, () => textBox.Text); return(textBox); } else { Container container = TypedElementConverter.CreateElement <Container>(); container.Separation = input.Separation; TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; container.Items.Add(textBlock); if (input.Value != null) { textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = input.Value; textBlock.Color = TextColor.Accent; textBlock.Wrap = true; container.Items.Add(textBlock); } return(context.Render(container)); } }
public override void FillCopy(Element copyElement, Model targetModel, ElementCopiesMap createdCopies) { base.FillCopy(copyElement, targetModel, createdCopies); TypedElement copyTypedElement = (TypedElement)copyElement; if (Type != null) { if (createdCopies.ContainsKey(Type)) { copyTypedElement.Type = (DataType)createdCopies[Type]; } else { if (Schema == targetModel.Schema) { if (Type is SimpleDataType) { copyTypedElement.Type = Type; } else { //TODO: copy typed element throw new NotImplementedException(); } } } } }
protected static HtmlTag NumberInputRender(TypedElement element, RenderContext context) { NumberInput input = (NumberInput)element; var uiNumberInput = new HtmlTag("input") .Attr("name", input.Id) .AddClass("ac-input") .AddClass("ac-numberInput") .Attr("type", "number") .Style("width", "100%"); if (!double.IsNaN(input.Min)) { uiNumberInput.Attr("min", input.Min.ToString()); } if (!double.IsNaN(input.Max)) { uiNumberInput.Attr("max", input.Max.ToString()); } if (!double.IsNaN(input.Value)) { uiNumberInput.Attr("value", input.Value.ToString()); } return(uiNumberInput); }
public SeparationConfig GetElementSeparation(TypedElement element) { switch (element.Type) { case TextBlock.TYPE: TextBlock tb = (TextBlock)element; switch (tb.Size) { case TextSize.Small: return(this.Config.TextBlock.Separations.Small); case TextSize.Medium: return(this.Config.TextBlock.Separations.Medium); case TextSize.Large: return(this.Config.TextBlock.Separations.Large); case TextSize.ExtraLarge: return(this.Config.TextBlock.Separations.ExtraLarge); case TextSize.Normal: default: return(this.Config.TextBlock.Separations.Normal); } case Image.TYPE: return(this.Config.Image.Separation); case Container.TYPE: return(this.Config.Container.Separation); case ColumnSet.TYPE: return(this.Config.ColumnSet.Separation); case Column.TYPE: return(this.Config.Column.Separation); case ActionSet.TYPE: return(this.Config.Actions.Separation); case ImageSet.TYPE: return(this.Config.ImageSet.Separation); case ChoiceSet.TYPE: return(this.Config.ChoiceSet.Separation); case TextInput.TYPE: return(this.Config.ImageSet.Separation); case DateInput.TYPE: return(this.Config.DateInput.Separation); case TimeInput.TYPE: return(this.Config.TimeInput.Separation); case NumberInput.TYPE: return(this.Config.NumberInput.Separation); } throw new Exception("Unknown type " + element.Type); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { TimeInput input = (TimeInput)element; if (context.Config.SupportsInteractivity) { var timePicker = new TimePicker(); DateTime value; if (DateTime.TryParse(input.Value, out value)) { timePicker.Value = value; } TimeSpan minValue; if (TimeSpan.TryParse(input.Min, out minValue)) { timePicker.EndTime = minValue; } TimeSpan maxValue; if (TimeSpan.TryParse(input.Max, out maxValue)) { timePicker.EndTime = maxValue; } timePicker.Watermark = input.Placeholder; timePicker.Style = context.GetStyle("Adaptive.Input.Time"); timePicker.DataContext = input; context.InputBindings.Add(input.Id, () => timePicker.Text); return(timePicker); } else { var textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; return(context.Render(textBlock)); } }
protected static HtmlTag ToggleInputRender(TypedElement element, RenderContext context) { ToggleInput toggleInput = (ToggleInput)element; var uiElement = new HtmlTag("div") .AddClass("ac-input") .Style("width", "100%"); var uiCheckboxInput = new HtmlTag("input") .Attr("type", "checkbox") .Attr("name", toggleInput.Id) .Style("display", "inline-block") .Style("vertical-align", "middle") .Style("margin", "0px"); if (toggleInput.Value == toggleInput.ValueOn) { uiCheckboxInput.Attr("checked", string.Empty); } var uiLabel = context.Render(new TextBlock { Text = toggleInput.Title }) .Style("display", "inline-block") .Style("margin-left", "6px") .Style("vertical-align", "middle"); return(uiElement.Append(uiCheckboxInput).Append(uiLabel)); }
protected static HtmlTag OpenUrlActionRender(TypedElement actionElement, RenderContext context) { OpenUrlAction action = (OpenUrlAction)actionElement; if (!context.Config.SupportsInteractivity) { return(null); } var buttonElement = new HtmlTag("button") { Text = action.Title } .Attr("type", "button") .Attr("url", action.Url) .Style("overflow", "hidden") .Style("white-space", "nowrap") .Style("text-overflow", "ellipsis") .Style("flex", context.Config.Actions.ActionAlignment == HorizontalAlignment.Stretch ? "0 1 100%" : "0 1 auto") .AddClass("ac-pushButton") .AddClass("ac-openUrlAction"); return(buttonElement); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { SubmitAction action = (SubmitAction)element; if (context.Config.SupportsInteractivity) { Button uiButton = XamlUtilities.CreateActionButton(action, context); // content uiButton.Click += (sender, e) => { try { dynamic data = (action.Data != null) ? ((JToken)action.Data).DeepClone() : new JObject(); data = context.MergeInputData(data); context.Action(uiButton, new ActionEventArgs() { Action = action, Data = data }); } catch (MissingInputException err) { context.MissingInput(action, new MissingInputEventArgs(err.Input, err.FrameworkElement)); } }; return(uiButton); } return(null); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { AdaptiveCard card = (AdaptiveCard)element; var outerGrid = new Grid(); outerGrid.Style = context.GetStyle("Adaptive.Card"); #if WPF //TODO for Xamarin outerGrid.Background = context.GetColorBrush(context.Config.AdaptiveCard.BackgroundColor); #endif outerGrid.SetBackgroundSource(card.BackgroundImage, context); var grid = new Grid(); grid.Style = context.GetStyle("Adaptive.InnerCard"); grid.Margin = new Thickness(context.Config.AdaptiveCard.Padding.Left, context.Config.AdaptiveCard.Padding.Top, context.Config.AdaptiveCard.Padding.Right, context.Config.AdaptiveCard.Padding.Bottom); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); var inputControls = new List <FrameworkElement>(); XamlContainer.AddContainerElements(grid, card.Body, context); XamlActionSet.AddActions(grid, card.Actions, context); outerGrid.Children.Add(grid); return(outerGrid); }
protected static HtmlTag ActionSetRender(TypedElement element, RenderContext context) { ActionSet actionSet = (ActionSet)element; var uiContainer = new DivTag() .AddClass($"ac-{element.Type.Replace(".", "").ToLower()}"); AddContainerElements(uiContainer, null, actionSet.Actions, context); return(uiContainer); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { ActionSet actionSet = (ActionSet)element; var uiContainer = new Grid(); uiContainer.Style = context.GetStyle("Adaptive.ActionSet"); AddActions(uiContainer, actionSet.Actions, context); return(uiContainer); }
protected static HtmlTag ShowCardActionRender(TypedElement actionElement, RenderContext context) { ShowCardAction action = (ShowCardAction)actionElement; if (context.Config.SupportsInteractivity) { var uiButton = new LinkTag(action.Title, null, $"ac-{action.Type.Replace(".", "").ToLower()}", "ac-action"); return(uiButton); } return(null); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { TextInput input = (TextInput)element; if (context.Config.SupportsInteractivity) { var textBox = new TextBox() { Text = input.Value }; if (input.IsMultiline == true) { textBox.AcceptsReturn = true; #if WPF textBox.TextWrapping = TextWrapping.Wrap; textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; #elif XAMARIN // TODO #endif } #if WPF if (input.MaxLength > 0) { textBox.MaxLength = input.MaxLength; } #elif XAMARIN // TODO #endif textBox.SetPlaceholder(input.Placeholder); textBox.Style = context.GetStyle($"Adaptive.Input.Text.{input.Style}"); textBox.SetContext(input); context.InputBindings.Add(input.Id, () => textBox.Text); return(textBox); } else { Container container = TypedElementConverter.CreateElement <Container>(); container.Separation = input.Separation; TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; container.Items.Add(textBlock); if (input.Value != null) { textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = input.Value; textBlock.Color = TextColor.Accent; textBlock.Wrap = true; container.Items.Add(textBlock); } return(context.Render(container)); } }
public static string GetTypeString(TypedElement te) { var type = te.Type ?? te.Ref; switch (type) { case "array": return(string.Format("List<{0}>", GetTypeString(te.Items))); default: { SwaggerTypes.WithPrimitiveType(type, te.Format, tcn => type = SwaggerTypeMappings[tcn]); return(type); } } }
public static FrameworkElement Render(TypedElement element, RenderContext context) { Image image = (Image)element; var uiImage = new UI.Image(); uiImage.SetSource(image.Url, context); uiImage.SetHorizontalAlignment(image.HorizontalAlignment); string style = $"Adaptive.{image.Type}"; if (image.Style == ImageStyle.Person) { style += $".{image.Style}"; #if WPF var mask = new RadialGradientBrush() { GradientOrigin = new Point(0.5, 0.5), Center = new Point(0.5, 0.5), RadiusX = 0.5, RadiusY = 0.5, GradientStops = new GradientStopCollection() }; mask.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#ffffffff"), .9)); mask.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#00ffffff"), 1.0)); uiImage.OpacityMask = mask; #elif XAMARIN //TODO #endif } uiImage.Style = context.GetStyle(style); uiImage.SetImageProperties(image, context); if (image.SelectAction != null) { var uiButton = (Button)context.Render(image.SelectAction); if (uiButton != null) { uiButton.Content = uiImage; uiButton.Style = context.GetStyle("Adaptive.Action.Tap"); return(uiButton); } } return(uiImage); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { ShowCardAction action = (ShowCardAction)element; if (context.Config.SupportsInteractivity) { Button uiButton = XamlUtilities.CreateActionButton(action, context); uiButton.Click += (sender, e) => { context.Action(uiButton, new ActionEventArgs() { Action = action, Data = null }); }; return(uiButton); } return(null); }
protected static HtmlTag ImageSetRender(TypedElement element, RenderContext context) { ImageSet imageSet = (ImageSet)element; var uiImageSet = new DivTag() .AddClass(imageSet.Type.ToLower()); foreach (var image in imageSet.Images) { if (imageSet.ImageSize != ImageSize.Auto) { image.Size = imageSet.ImageSize; } var uiImage = context.Render(image); uiImage = uiImage.Style("display", "inline-block"); uiImageSet.Children.Add(uiImage); } return(uiImageSet); }
protected static HtmlTag TextInputRender(TypedElement element, RenderContext context) { TextInput input = (TextInput)element; HtmlTag uiTextInput; if (input.IsMultiline) { uiTextInput = new HtmlTag("textarea"); if (!string.IsNullOrEmpty(input.Value)) { uiTextInput.Text = input.Value; } } else { uiTextInput = new HtmlTag("input").Attr("type", "text"); if (!string.IsNullOrEmpty(input.Value)) { uiTextInput.Attr("value", input.Value); } } uiTextInput .Attr("name", input.Id) .AddClass("ac-textinput") .AddClass("ac-input") .Style("width", "100%"); if (!string.IsNullOrEmpty(input.Placeholder)) { uiTextInput.Attr("placeholder", input.Placeholder); } if (input.MaxLength > 0) { uiTextInput.Attr("maxLength", input.MaxLength.ToString()); } return(uiTextInput); }
protected static HtmlTag ChoiceSetRender(TypedElement element, RenderContext context) { ChoiceSet choiceSet = (ChoiceSet)element; var choiceText = GetFallbackText(choiceSet); if (choiceText == null) { var choices = choiceSet.Choices.Select(choice => choice.Title).ToList(); if (choiceSet.Style == ChoiceInputStyle.Compact) { if (choiceSet.IsMultiSelect) { choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " and ")}"; } else { choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " or ")}"; } } else // if (this.Style == ChoiceInputStyle.Expanded) { choiceText = $"* {RendererUtilities.JoinString(choices, "\n* ", "\n* ")}"; } } var container = new Container { Separation = choiceSet.Separation }; container.Items.Add(new TextBlock { Text = choiceText, Wrap = true }); container.Items.Add(new TextBlock { Text = RendererUtilities.JoinString(choiceSet.Choices.Where(c => c.IsSelected).Select(c => c.Title).ToList(), ", ", " and "), Color = TextColor.Accent, Wrap = true }); return(context.Render(container)); }
protected static HtmlTag FactSetRender(TypedElement element, RenderContext context) { FactSet factSet = (FactSet)element; var uiFactSet = (TableTag) new TableTag() .AddClass($"ac-{element.Type.Replace(".", "").ToLower()}") .Style("overflow", "hidden"); foreach (var fact in factSet.Facts) { TextBlock factTitle = new TextBlock() { Text = fact.Title, Size = context.Config.FactSet.Title.Size, Color = context.Config.FactSet.Title.Color, Weight = context.Config.FactSet.Title.Weight, IsSubtle = context.Config.FactSet.Title.IsSubtle, }; var uiTitle = context.Render(factTitle) .AddClass("ac-facttitle") .Style("margin-right", $"{context.Config.FactSet.Spacing}px"); TextBlock factValue = new TextBlock() { Text = fact.Value, Size = context.Config.FactSet.Value.Size, Color = context.Config.FactSet.Value.Color, Weight = context.Config.FactSet.Value.Weight, IsSubtle = context.Config.FactSet.Value.IsSubtle, }; var uiValue = context.Render(factValue) .AddClass("ac-factvalue"); // create row in factset var uiRow = uiFactSet .AddBodyRow(); // add elements as cells uiRow.AddCell().AddClass("ac-factset-titlecell").Append(uiTitle); uiRow.AddCell().AddClass("ac-factset-valuecell").Append(uiValue); } return(uiFactSet); }
protected static HtmlTag AdaptiveCardRender(TypedElement element, RenderContext context) { AdaptiveCard card = (AdaptiveCard)element; var uiCard = new DivTag() .AddClass($"ac-{card.Type.ToLower()}") .Style("width", "100%") .Style("background-color", context.GetRGBColor(context.Config.AdaptiveCard.BackgroundColor)) .Style("box-sizing", "border-box"); if (card.BackgroundImage != null) { uiCard = uiCard.Style("background-image", $"url('{card.BackgroundImage}')") .Style("background-repeat", "no-repeat") .Style("background-size", "cover"); } AddContainerElements(uiCard, card.Body, card.Actions, context); return(uiCard); }
protected static HtmlTag NumberInputRender(TypedElement element, RenderContext context) { NumberInput input = (NumberInput)element; var container = new Container { Separation = input.Separation }; container.Items.Add(new TextBlock { Text = GetFallbackText(input) ?? input.Placeholder }); if (!double.IsNaN(input.Value)) { container.Items.Add(new TextBlock { Text = input.Value.ToString(), Color = TextColor.Accent, Wrap = true }); } return(context.Render(container)); }
protected static HtmlTag ContainerRender(TypedElement element, RenderContext context) { Container container = (Container)element; var uiContainer = new DivTag() .AddClass($"ac-{element.Type.Replace(".", "").ToLower()}"); AddContainerElements(uiContainer, container.Items, null, context); if (context.Config.SupportsInteractivity && container.SelectAction != null) { //var uiButton = (Button)RenderAction(container.SelectAction, new RenderContext(this.actionCallback, this.missingDataCallback)); //if (uiButton != null) //{ // uiButton.Content = uiContainer; // uiButton.Style = this.GetStyle("Adaptive.Action.Tap"); // return uiButton; //} } return(uiContainer); }
protected static HtmlTag TimeInputRender(TypedElement element, RenderContext context) { TimeInput input = (TimeInput)element; var container = new Container { Separation = input.Separation }; container.Items.Add(new TextBlock { Text = GetFallbackText(input) ?? input.Placeholder }); if (input.Value != null) { container.Items.Add(new TextBlock { Text = input.Value, Color = TextColor.Accent, Wrap = true }); } return(context.Render(container)); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { ToggleInput input = (ToggleInput)element; if (context.Config.SupportsInteractivity) { var uiToggle = new CheckBox(); #if WPF // TODO: Finish switch uiToggle.Content = input.Title; #endif uiToggle.SetState(input.Value == (input.ValueOn ?? "true")); uiToggle.Style = context.GetStyle($"Adaptive.Input.Toggle"); uiToggle.SetContext(input); context.InputBindings.Add(input.Id, () => { return(uiToggle.GetState() == true ? input.ValueOn ?? "true" : input.ValueOff ?? "false"); }); return(uiToggle); } else { Container container = TypedElementConverter.CreateElement <Container>(); container.Separation = input.Separation; TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input); container.Items.Add(textBlock); if (input.Value != null) { textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = (input.Value == (input.ValueOn ?? "true")) ? input.ValueOn ?? "selected" : input.ValueOff ?? "not selected"; textBlock.Color = TextColor.Accent; textBlock.Wrap = true; container.Items.Add(textBlock); } return(context.Render(container)); } }
public static FrameworkElement Render(TypedElement element, RenderContext context) { Column column = (Column)element; var uiContainer = new Grid(); uiContainer.Style = context.GetStyle("Adaptive.Column"); XamlContainer.AddContainerElements(uiContainer, column.Items, context); if (column.SelectAction != null) { var uiButton = (Button)context.Render(column.SelectAction);//, new RenderContext(this.actionCallback, this.missingDataCallback)); if (uiButton != null) { uiButton.Content = uiContainer; uiButton.Style = context.GetStyle("Adaptive.Action.Tap"); return(uiButton); } } return(uiContainer); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { ImageSet imageSet = (ImageSet)element; #if WPF var uiImageSet = new ListBox(); ScrollViewer.SetHorizontalScrollBarVisibility(uiImageSet, ScrollBarVisibility.Disabled); var itemsPanelTemplate = new ItemsPanelTemplate(); var factory = new FrameworkElementFactory(typeof(WrapPanel)); // factory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); itemsPanelTemplate.VisualTree = factory; uiImageSet.ItemsPanel = itemsPanelTemplate; #elif XAMARIN var uiImageSet = new StackLayout { Orientation = StackOrientation.Vertical }; #endif uiImageSet.Style = context.GetStyle("Adaptive.ImageSet"); foreach (var image in imageSet.Images) { if (image.Size == ImageSize.Auto) { if (imageSet.ImageSize != ImageSize.Auto) { image.Size = imageSet.ImageSize; } else { image.Size = context.Config.ImageSet.ImageSize; } } var uiImage = context.Render(image); uiImageSet.Add(uiImage); } return(uiImageSet); }
/// <summary> /// Implements the constructor: TypedElement() /// </summary> public virtual void TypedElement(TypedElement @this) { }