public static FrameworkElement Render(AdaptiveCard card, RenderContext context) { var outerGrid = new Grid(); outerGrid.Style = context.GetStyle("Adaptive.Card"); #if WPF //TODO for Xamarin outerGrid.Background = context.GetColorBrush(context.Config.ContainerStyles.Default.BackgroundColor); #endif outerGrid.SetBackgroundSource(card.BackgroundImage, context); var grid = new Grid(); grid.Style = context.GetStyle("Adaptive.InnerCard"); grid.Margin = new Thickness(context.Config.Spacing.Padding, context.Config.Spacing.Padding, context.Config.Spacing.Padding, context.Config.Spacing.Padding); 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); }
public static Button CreateActionButton(ActionBase action, RenderContext context) { ActionConfig styling = context.Config.Actions; var uiButton = new Button() { #if WPF HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, #endif }; uiButton.SetBackgroundColor(styling.BackgroundColor, context); uiButton.SetBorderColor(styling.BackgroundColor, context); uiButton.SetThickness(context.Config.Actions.BorderThickness); uiButton.Style = context.GetStyle($"Adaptive.{action.Type}"); xaml.TextBlock uiTitle = new xaml.TextBlock() { Text = action.Title, FontSize = styling.FontSize, Margin = new Thickness(styling.Padding.Left, styling.Padding.Top, styling.Padding.Right, styling.Padding.Bottom), }; uiTitle.SetFontWeight(styling.FontWeight); uiTitle.SetColor(styling.TextColor, context); uiTitle.Style = context.GetStyle($"Adaptive.Action.Title"); uiButton.Content = uiTitle; string name = context.GetType().Name.Replace("Action", String.Empty); return(uiButton); }
public static FrameworkElement Render(Container container, RenderContext context) { var containerStyle = context.Config.ContainerStyles.Default; var uiContainer = new Grid(); uiContainer.Margin = new Thickness(context.Config.Spacing.Padding); uiContainer.Style = context.GetStyle("Adaptive.Container"); AddContainerElements(uiContainer, container.Items, context); if (container.SelectAction != null) { var uiButton = (Button)context.Render(container.SelectAction);//, new RenderContext(container.actionCallback, container.missingDataCallback)); if (uiButton != null) { uiButton.Content = uiContainer; uiButton.Style = context.GetStyle("Adaptive.Action.Tap"); return(uiButton); } } #if WPF Grid uiOuterContainer = new Grid(); uiOuterContainer.Background = context.GetColorBrush(containerStyle.BackgroundColor); uiOuterContainer.Children.Add(uiContainer); Border border = new Border(); border.Child = uiOuterContainer; return(border); #else // TODO for xamarin return(uiContainer); #endif }
public static FrameworkElement Render(NumberInput input, RenderContext context) { if (context.Config.SupportsInteractivity) { IntegerUpDown numberPicker = new IntegerUpDown(); // numberPicker.ShowButtonSpinner = true; if (!Double.IsNaN(input.Value)) { numberPicker.Value = Convert.ToInt32(input.Value); } if (!Double.IsNaN(input.Min)) { numberPicker.Minimum = Convert.ToInt32(input.Min); } if (!Double.IsNaN(input.Max)) { numberPicker.Minimum = Convert.ToInt32(input.Max); } numberPicker.Watermark = input.Placeholder; numberPicker.Style = context.GetStyle("Adaptive.Input.Number"); numberPicker.DataContext = input; context.InputBindings.Add(input.Id, () => numberPicker.Value?.ToString()); return(numberPicker); } else { var textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; return(context.Render(textBlock)); } }
public static void AddSeperator(RenderContext context, CardElement element, Grid uiContainer) { if (element.Spacing == Spacing.None && !element.Separator) { return; } var uiSep = new Grid(); uiSep.Style = context.GetStyle($"Adaptive.Separator"); int spacing = context.Config.GetSpacing(element.Spacing); SeparatorConfig sepStyle = context.Config.Separator; uiSep.Margin = new Thickness(0, (spacing - sepStyle.LineThickness) / 2, 0, (spacing - sepStyle.LineThickness) / 2); uiSep.SetHeight(sepStyle.LineThickness); if (!string.IsNullOrWhiteSpace(sepStyle.LineColor)) { uiSep.SetBackgroundColor(sepStyle.LineColor, context); } uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiSep, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiSep); }
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 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)); } }
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)); } }
public static FrameworkElement Render(TextInput input, RenderContext context) { 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) { 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 System.Windows.Controls.TextBlock CreateControl(TextBlock textBlock, RenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text); // uiTextBlock.Text = textBlock.Text; string xaml = $"<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader); uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}"); uiTextBlock.FontFamily = new FontFamily(context.Config.FontFamily); uiTextBlock.TextWrapping = TextWrapping.NoWrap; switch (textBlock.Weight) { case TextWeight.Bolder: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(700); break; case TextWeight.Lighter: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(300); break; case TextWeight.Default: default: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(400); break; } uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.HorizontalAlignment != HorizontalAlignment.Left) { System.Windows.HorizontalAlignment alignment; if (Enum.TryParse <System.Windows.HorizontalAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.HorizontalAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
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); }
public static FrameworkElement Render(Column column, RenderContext context) { 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) { 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 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 void AddActions(Grid uiContainer, List <ActionBase> actions, RenderContext context) { var actionsToProcess = actions .Take(context.Config.Actions.MaxActions).ToList(); if (!actionsToProcess.Any()) { return; } // TODO: Bring back UniformGrid //var uiActionBar = new UniformGrid(); var uiActionBar = new Grid(); //uiActionBar.Rows = 1; //uiActionBar.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; //uiActionBar.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; int iCol = 0; foreach (var action in actionsToProcess) { // add actions var uiAction = context.Render(action); if (uiAction != null) { Grid.SetColumn(uiAction, iCol++); uiActionBar.Children.Add(uiAction); } } uiActionBar.Style = context.GetStyle("Adaptive.Actions"); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiActionBar); }
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); }
public static Xamarin.Forms.TextBlock CreateControl(TextBlock textBlock, RenderContext context) { var uiTextBlock = new Xamarin.Forms.TextBlock(); uiTextBlock.Text = RendererUtilities.ApplyTextFunctions(textBlock.Text); uiTextBlock.Style = context.GetStyle("Adaptive.TextBlock"); // TODO: confirm text trimming uiTextBlock.LineBreakMode = LineBreakMode.TailTruncation; switch (textBlock.HorizontalAlignment) { case HorizontalAlignment.Left: uiTextBlock.HorizontalTextAlignment = TextAlignment.Start; break; case HorizontalAlignment.Center: uiTextBlock.HorizontalTextAlignment = TextAlignment.Center; break; case HorizontalAlignment.Right: uiTextBlock.HorizontalTextAlignment = TextAlignment.End; break; } uiTextBlock.TextColor = context.Resources.TryGetValue <Color>($"Adaptive.{textBlock.Color}"); if (textBlock.Weight == TextWeight.Bolder) { uiTextBlock.FontAttributes = FontAttributes.Bold; } if (textBlock.Wrap == true) { uiTextBlock.LineBreakMode = LineBreakMode.WordWrap; } return(uiTextBlock); }
public static void AddSeperator(RenderContext context, CardElement element, Grid uiContainer, SeparationStyle seperationStyle) { if (seperationStyle == SeparationStyle.None) { return; } var uiSep = new Grid(); uiSep.Style = context.GetStyle($"Adaptive.Separator"); SeparationConfig sepStyle = null; switch (seperationStyle) { case SeparationStyle.Default: sepStyle = context.Config.GetSeparationForElement(element, strong: false); break; case SeparationStyle.Strong: sepStyle = context.Config.GetSeparationForElement(element, strong: true); break; } uiSep.Margin = new Thickness(0, (sepStyle.Spacing - sepStyle.LineThickness) / 2, 0, (sepStyle.Spacing - sepStyle.LineThickness) / 2); uiSep.SetHeight(sepStyle.LineThickness); if (!string.IsNullOrWhiteSpace(sepStyle.LineColor)) { uiSep.SetBackgroundColor(sepStyle.LineColor, context); } uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiSep, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiSep); }
public static void AddActions(Grid uiContainer, List <ActionBase> actions, RenderContext context) { var maxActions = context.Config.Actions.MaxActions; var actionsToProcess = actions .Take(maxActions).ToList(); if (actionsToProcess.Any() == true) { var uiActionBar = new UniformGrid(); if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal) { uiActionBar.Columns = actionsToProcess.Count(); } else { uiActionBar.Rows = actionsToProcess.Count(); } uiActionBar.HorizontalAlignment = (System.Windows.HorizontalAlignment)Enum.Parse(typeof(System.Windows.HorizontalAlignment), context.Config.Actions.ActionAlignment.ToString()); uiActionBar.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; uiActionBar.Style = context.GetStyle("Adaptive.Actions"); if (uiContainer.RowDefinitions.Count > 0) { XamlContainer.AddSeperator(context, new Container(), uiContainer); } uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiActionBar); bool isInline = (context.Config.Actions.ShowCard.ActionMode == ShowCardActionMode.Inline); if (isInline && actionsToProcess.Where(a => a is ShowCardAction).Any()) { uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); } int iPos = 0; List <FrameworkElement> actionBarCards = new List <FrameworkElement>(); foreach (var action in actionsToProcess) { // add actions var uiAction = (Button)context.Render(action); if (uiAction != null) { if (uiActionBar.Children.Count > 0) { if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal) { uiAction.Margin = new Thickness(context.Config.Actions.ButtonSpacing, 0, 0, 0); } else { uiAction.Margin = new Thickness(0, context.Config.Actions.ButtonSpacing, 0, 0); } } if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal) { Grid.SetColumn(uiAction, iPos++); } uiActionBar.Children.Add(uiAction); if (action is ShowCardAction) { ShowCardAction showCardAction = (ShowCardAction)action; if (isInline) { Grid uiShowCardContainer = new Grid(); uiShowCardContainer.Style = context.GetStyle("Adaptive.Actions.ShowCard"); uiShowCardContainer.DataContext = showCardAction; uiShowCardContainer.Margin = new Thickness(0, context.Config.Actions.ShowCard.InlineTopMargin, 0, 0); uiShowCardContainer.Visibility = Visibility.Collapsed; // render the card var uiShowCard = context.Render(showCardAction.Card); ((Grid)uiShowCard).Background = context.GetColorBrush("Transparent"); uiShowCard.DataContext = showCardAction; uiShowCardContainer.Children.Add(uiShowCard); actionBarCards.Add(uiShowCardContainer); Grid.SetRow(uiShowCardContainer, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiShowCardContainer); uiAction.Click += (sender, e) => { bool showCard = (uiShowCardContainer.Visibility != Visibility.Visible); foreach (var actionBarCard in actionBarCards) { actionBarCard.Visibility = Visibility.Collapsed; } if (showCard) { uiShowCardContainer.Visibility = Visibility.Visible; } }; } } } } } }
public static FrameworkElement Render(TypedElement element, RenderContext context) { FactSet factSet = (FactSet)element; var uiFactSet = new Grid(); // grid.Margin = factSet.Theme.FactSetMargins; uiFactSet.Style = context.GetStyle("Adaptive.FactSet"); uiFactSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); uiFactSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); int iRow = 0; foreach (var fact in factSet.Facts) { var uiTitle = context.Render(new TextBlock() { Size = context.Config.FactSet.Title.Size, Color = context.Config.FactSet.Title.Color, IsSubtle = context.Config.FactSet.Title.IsSubtle, Weight = context.Config.FactSet.Title.Weight, Wrap = context.Config.FactSet.Title.Wrap, Text = fact.Title }); #if WPF uiTitle.Style = context.GetStyle("Adaptive.Fact.Title"); uiTitle.Margin = new Thickness(left: 0, top: 0, right: context.Config.FactSet.Spacing, bottom: 0); #elif XAMARIN //TODO #endif var uiValue = context.Render(new TextBlock() { Size = context.Config.FactSet.Value.Size, Color = context.Config.FactSet.Value.Color, IsSubtle = context.Config.FactSet.Value.IsSubtle, Weight = context.Config.FactSet.Value.Weight, Wrap = context.Config.FactSet.Value.Wrap, Text = fact.Value }); #if WPF uiValue.Style = context.GetStyle("Adaptive.Fact.Value"); #elif XAMARIN //TODO #endif uiFactSet.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetColumn(uiTitle, 0); Grid.SetRow(uiTitle, iRow); uiFactSet.Children.Add(uiTitle); Grid.SetColumn(uiValue, 1); Grid.SetRow(uiValue, iRow++); uiFactSet.Children.Add(uiValue); } return(uiFactSet); }
public static FrameworkElement Render(TypedElement element, RenderContext context) { ColumnSet columnSet = (ColumnSet)element; var uiColumnSet = new Grid(); uiColumnSet.Style = context.GetStyle($"Adaptive.{columnSet.Type}"); foreach (var column in columnSet.Columns) { FrameworkElement uiContainer = context.Render(column); // Add vertical Seperator if (uiColumnSet.ColumnDefinitions.Count > 0) { if (column.Separation != SeparationStyle.None) { var uiSep = new Grid(); uiSep.Style = context.GetStyle($"Adaptive.VerticalSeparator"); #if WPF uiSep.VerticalAlignment = VerticalAlignment.Stretch; #elif XAMARIN // TOOD: check xamarin separator visual //sep.VerticalAlignment = VerticalAlignment.Stretch; #endif SeparationConfig sepStyle; switch (column.Separation) { case SeparationStyle.Strong: sepStyle = context.Config.GetSeparationForElement(element, true); break; case SeparationStyle.Default: default: sepStyle = context.Config.GetSeparationForElement(element, false); break; } uiSep.Margin = new Thickness(sepStyle.Spacing / 2, 0, sepStyle.Spacing / 2, 0); #if WPF uiSep.Width = sepStyle.LineThickness; if (sepStyle.LineColor != null) { uiSep.Background = context.GetColorBrush(sepStyle.LineColor); } #elif XAMARIN // TODO #endif uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); Grid.SetColumn(uiSep, uiColumnSet.ColumnDefinitions.Count - 1); uiColumnSet.Children.Add(uiSep); } } // do some sizing magic using the magic GridUnitType.Star var size = column.Size?.ToLower(); if (size == null || size == ColumnSize.Stretch.ToLower()) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); } else if (size == ColumnSize.Auto.ToLower()) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } else { double val; if (double.TryParse(size, out val)) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(val, GridUnitType.Star) }); } else { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } } Grid.SetColumn(uiContainer, uiColumnSet.ColumnDefinitions.Count - 1); uiColumnSet.Children.Add(uiContainer); } return(uiColumnSet); }
public static FrameworkElement Render(ColumnSet columnSet, RenderContext context) { var uiColumnSet = new Grid(); uiColumnSet.Style = context.GetStyle($"Adaptive.{columnSet.Type}"); foreach (var column in columnSet.Columns) { FrameworkElement uiContainer = context.Render(column); // Add vertical Seperator if (uiColumnSet.ColumnDefinitions.Count > 0) { if (column.Separator || column.Spacing != Spacing.None) { var uiSep = new Grid(); uiSep.Style = context.GetStyle($"Adaptive.VerticalSeparator"); #if WPF uiSep.VerticalAlignment = VerticalAlignment.Stretch; #elif XAMARIN // TOOD: check xamarin separator visual //sep.VerticalAlignment = VerticalAlignment.Stretch; #endif int spacing = context.Config.GetSpacing(column.Spacing); uiSep.Margin = new Thickness(spacing / 2.0, 0, spacing / 2.0, 0); #if WPF uiSep.Width = context.Config.Separator.LineThickness; if (column.Separator && context.Config.Separator.LineColor != null) { uiSep.Background = context.GetColorBrush(context.Config.Separator.LineColor); } #elif XAMARIN // TODO #endif uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); Grid.SetColumn(uiSep, uiColumnSet.ColumnDefinitions.Count - 1); uiColumnSet.Children.Add(uiSep); } } // do some sizing magic using the magic GridUnitType.Star var width = column.Width?.ToLower(); if (string.IsNullOrEmpty(width)) #pragma warning disable CS0618 // Type or member is obsolete { width = column.Size?.ToLower(); } #pragma warning restore CS0618 // Type or member is obsolete if (width == null || width == ColumnWidth.Stretch.ToLower()) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); } else if (width == ColumnWidth.Auto.ToLower()) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } else { double val; if (double.TryParse(width, out val)) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(val, GridUnitType.Star) }); } else { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } } Grid.SetColumn(uiContainer, uiColumnSet.ColumnDefinitions.Count - 1); uiColumnSet.Children.Add(uiContainer); } if (columnSet.SelectAction != null) { var uiButton = (Button)context.Render(columnSet.SelectAction); if (uiButton != null) { uiButton.Content = uiColumnSet; uiButton.Style = context.GetStyle("Adaptive.Action.Tap"); return(uiButton); } } return(uiColumnSet); }
public static FrameworkElement Render(ChoiceSet choiceSet, RenderContext context) { var chosen = choiceSet.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>(); #if WPF if (context.Config.SupportsInteractivity) { var uiGrid = new Grid(); uiGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); uiGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); var uiComboBox = new ComboBox(); uiComboBox.Style = context.GetStyle("Adaptive.Input.ChoiceSet.ComboBox"); uiComboBox.DataContext = choiceSet; var uiChoices = new ListBox(); ScrollViewer.SetHorizontalScrollBarVisibility(uiChoices, ScrollBarVisibility.Disabled); var itemsPanelTemplate = new ItemsPanelTemplate(); var factory = new FrameworkElementFactory(typeof(WrapPanel)); itemsPanelTemplate.VisualTree = factory; uiChoices.ItemsPanel = itemsPanelTemplate; uiChoices.DataContext = choiceSet; uiChoices.Style = context.GetStyle("Adaptive.Input.ChoiceSet"); foreach (var choice in choiceSet.Choices) { if (choiceSet.IsMultiSelect == true) { var uiCheckbox = new CheckBox(); uiCheckbox.Content = choice.Title; uiCheckbox.IsChecked = chosen.Contains(choice.Value); uiCheckbox.DataContext = choice; uiCheckbox.Style = context.GetStyle("Adaptive.Input.ChoiceSet.CheckBox"); uiChoices.Items.Add(uiCheckbox); } else { if (choiceSet.Style == ChoiceInputStyle.Compact) { var uiComboItem = new ComboBoxItem(); uiComboItem.Style = context.GetStyle("Adaptive.Input.ChoiceSet.ComboBoxItem"); uiComboItem.Content = choice.Title; uiComboItem.DataContext = choice; uiComboBox.Items.Add(uiComboItem); if (chosen.Contains(choice.Value)) { uiComboBox.SelectedItem = uiComboItem; } } else { var uiRadio = new RadioButton(); uiRadio.Content = choice.Title; uiRadio.IsChecked = chosen.Contains(choice.Value); uiRadio.GroupName = choiceSet.Id; uiRadio.DataContext = choice; uiRadio.Style = context.GetStyle("Adaptive.Input.ChoiceSet.Radio"); uiChoices.Items.Add(uiRadio); } } } context.InputBindings.Add(choiceSet.Id, () => { if (choiceSet.IsMultiSelect == true) { string values = string.Empty; foreach (var item in uiChoices.Items) { CheckBox checkBox = (CheckBox)item; Choice choice = checkBox.DataContext as Choice; if (checkBox.IsChecked == true) { values += (values == string.Empty ? "" : ",") + choice.Value; } } return(values); } else { if (choiceSet.Style == ChoiceInputStyle.Compact) { ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem; if (item != null) { Choice choice = item.DataContext as Choice; return(choice.Value); } return(null); } else { foreach (var item in uiChoices.Items) { RadioButton radioBox = (RadioButton)item; Choice choice = radioBox.DataContext as Choice; if (radioBox.IsChecked == true) { return(choice.Value); } } return(null); } } }); if (choiceSet.Style == ChoiceInputStyle.Compact) { Grid.SetRow(uiComboBox, 1); uiGrid.Children.Add(uiComboBox); return(uiGrid); } else { Grid.SetRow(uiChoices, 1); uiGrid.Children.Add(uiChoices); return(uiGrid); } } #endif string choiceText = XamlUtilities.GetFallbackText(choiceSet); if (choiceText == null) { List <string> 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 (choiceSet.Style == ChoiceInputStyle.Expanded) { choiceText = $"* {RendererUtilities.JoinString(choices, "\n* ", "\n* ")}"; } } Container container = TypedElementConverter.CreateElement <Container>(); container.Separation = choiceSet.Separation; TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = choiceText; textBlock.Wrap = true; container.Items.Add(textBlock); textBlock = TypedElementConverter.CreateElement <TextBlock>(); textBlock.Text = RendererUtilities.JoinString(choiceSet.Choices.Where(c => chosen.Contains(c.Value)).Select(c => c.Title).ToList(), ", ", " and "); textBlock.Color = TextColor.Accent; textBlock.Wrap = true; container.Items.Add(textBlock); return(context.Render(container)); }