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 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 void SetBorderColor(this Button view, string color, RenderContext context) { view.BorderBrush = context.GetColorBrush(color); }
public static void SetBackgroundColor(this Button panel, string color, RenderContext context) { panel.Background = context.GetColorBrush(color); }
public static void SetBackgroundColor(this System.Windows.Controls.Panel panel, string color, RenderContext context) { panel.Background = context.GetColorBrush(color); }
public static void SetColor(this System.Windows.Controls.TextBlock textBlock, string color, RenderContext context) { textBlock.Foreground = context.GetColorBrush(color); }
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(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 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; } }; } } } } } }