private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text, context.Lang); // 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.TextWrapping = TextWrapping.NoWrap; uiTextBlock.FontFamily = new FontFamily(context.Config.GetFontFamily(textBlock.FontStyle)); uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textBlock.FontStyle, textBlock.Weight)); uiTextBlock.FontSize = context.Config.GetFontSize(textBlock.FontStyle, textBlock.Size); uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.Italic) { uiTextBlock.FontStyle = FontStyles.Italic; } if (textBlock.Strikethrough) { uiTextBlock.TextDecorations = TextDecorations.Strikethrough; } if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.TextAlignment alignment; if (Enum.TryParse <System.Windows.TextAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.TextAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
private static void AddInlineTextRun(TextBlock uiRichTB, AdaptiveTextRun textRun, AdaptiveRenderContext context) { Span textRunSpan; if (textRun.SelectAction != null && context.Config.SupportsInteractivity) { Hyperlink selectActionLink = new Hyperlink(); selectActionLink.Click += (sender, e) => { context.InvokeAction(uiRichTB, new AdaptiveActionEventArgs(textRun.SelectAction)); e.Handled = true; }; textRunSpan = selectActionLink as Span; } else { textRunSpan = new Span(); } // Handle Date/Time parsing string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang); textRunSpan.Inlines.Add(text); textRunSpan.Style = context.GetStyle($"Adaptive.{textRun.Type}"); textRunSpan.FontFamily = new FontFamily(RendererUtil.GetFontFamilyFromList(context.Config.GetFontFamily(textRun.FontType))); textRunSpan.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontType, textRun.Weight)); textRunSpan.FontSize = context.Config.GetFontSize(textRun.FontType, textRun.Size); if (textRun.Italic) { textRunSpan.FontStyle = FontStyles.Italic; } if (textRun.Strikethrough) { textRunSpan.TextDecorations = TextDecorations.Strikethrough; } if (textRun.Highlight) { textRunSpan.SetHighlightColor(textRun.Color, textRun.IsSubtle, context); } textRunSpan.SetColor(textRun.Color, textRun.IsSubtle, context); uiRichTB.Inlines.Add(textRunSpan); }
public static FrameworkElement Render(AdaptiveNumberInput input, AdaptiveRenderContext context) { var textBox = new TextBox() { Text = input.Value.ToString() }; textBox.SetPlaceholder(input.Placeholder); textBox.Style = context.GetStyle($"Adaptive.Input.Text.Number"); textBox.SetContext(input); context.InputBindings.Add(input.Id, () => textBox.Text); return(textBox); }
public static FrameworkElement Render(AdaptiveToggleInput input, AdaptiveRenderContext context) { var uiToggle = new CheckBox(); uiToggle.Content = input.Title; uiToggle.Foreground = context.GetColorBrush(context.Config.ContainerStyles.Default.ForegroundColors.Default.Default); uiToggle.SetState(input.Value == (input.ValueOn ?? "true")); uiToggle.Style = context.GetStyle($"Adaptive.Input.Toggle"); uiToggle.SetContext(input); context.InputBindings.Add(input.Id, () => uiToggle.GetState() == true ? input.ValueOn ?? "true" : input.ValueOff ?? "false"); return(uiToggle); }
public static FrameworkElement Render(AdaptiveColumn column, AdaptiveRenderContext context) { var uiContainer = new Grid(); uiContainer.Style = context.GetStyle("Adaptive.Column"); uiContainer.SetBackgroundSource(column.BackgroundImage, context); // Keep track of ContainerStyle.ForegroundColors before Container is rendered var parentRenderArgs = context.RenderArgs; var elementRenderArgs = new AdaptiveRenderArgs(parentRenderArgs); Border border = new Border(); border.Child = uiContainer; bool inheritsStyleFromParent = !column.Style.HasValue; bool columnHasPadding = false; if (!inheritsStyleFromParent) { columnHasPadding = AdaptiveContainerRenderer.ApplyPadding(border, uiContainer, column, parentRenderArgs, context); // Apply background color ContainerStyleConfig containerStyle = context.Config.ContainerStyles.GetContainerStyleConfig(column.Style); border.Background = context.GetColorBrush(containerStyle.BackgroundColor); elementRenderArgs.ForegroundColors = containerStyle.ForegroundColors; } elementRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : column.Style.Value; if ((parentRenderArgs.ColumnRelativePosition == ColumnPositionEnum.Begin) || (parentRenderArgs.ColumnRelativePosition == ColumnPositionEnum.End)) { elementRenderArgs.ColumnRelativePosition = ColumnPositionEnum.Intermediate; } elementRenderArgs.HasParentWithPadding = columnHasPadding; context.RenderArgs = elementRenderArgs; AdaptiveContainerRenderer.AddContainerElements(uiContainer, column.Items, context); RendererUtil.ApplyVerticalContentAlignment(uiContainer, column); RendererUtil.ApplyIsVisible(uiContainer, column); uiContainer.MinHeight = column.PixelMinHeight; // Revert context's value to that of outside the Column context.RenderArgs = parentRenderArgs; return(RendererUtil.ApplySelectAction(border, column, context)); }
public static FrameworkElement Render(AdaptiveContainer container, AdaptiveRenderContext context) { var uiContainer = new Grid(); //uiContainer.Margin = new Thickness(context.Config.Spacing.Padding); uiContainer.Style = context.GetStyle("Adaptive.Container"); if (container.Style != null) { // Apply background color var containerStyle = context.Config.ContainerStyles.Default; if (container.Style == AdaptiveContainerStyle.Emphasis) { containerStyle = context.Config.ContainerStyles.Emphasis; } uiContainer.SetBackgroundColor(containerStyle.BackgroundColor, context); } switch (container.VerticalContentAlignment) { case AdaptiveVerticalContentAlignment.Center: uiContainer.VerticalAlignment = VerticalAlignment.Center; break; case AdaptiveVerticalContentAlignment.Bottom: uiContainer.VerticalAlignment = VerticalAlignment.Bottom; break; case AdaptiveVerticalContentAlignment.Top: default: break; } AddContainerElements(uiContainer, container.Items, context); if (container.SelectAction != null) { return(context.RenderSelectAction(container.SelectAction, uiContainer)); } Grid uiOuterContainer = new Grid(); uiOuterContainer.Children.Add(uiContainer); Border border = new Border(); border.Child = uiOuterContainer; return(border); }
public static FrameworkElement RenderSelectAction(this AdaptiveRenderContext context, AdaptiveAction selectAction, FrameworkElement uiElement) { if (context.Config.SupportsInteractivity) { var uiButton = (Button)context.Render(selectAction); uiButton.HorizontalAlignment = HorizontalAlignment.Left; uiButton.Background = new SolidColorBrush(Colors.Transparent); uiButton.BorderThickness = new Thickness(0); uiButton.Content = uiElement; uiButton.Style = context.GetStyle("Adaptive.Action.Tap"); return(uiButton); } return(uiElement); }
public static FrameworkElement Render(AdaptiveColumn column, AdaptiveRenderContext context) { var uiContainer = new Grid(); uiContainer.Style = context.GetStyle("Adaptive.Column"); AdaptiveContainerRenderer.AddContainerElements(uiContainer, column.Items, context); if (column.SelectAction != null) { return(context.RenderSelectAction(column.SelectAction, uiContainer)); } return(uiContainer); }
public static FrameworkElement Render(AdaptiveContainer container, AdaptiveRenderContext context) { var uiContainer = new Grid(); uiContainer.Style = context.GetStyle("Adaptive.Container"); uiContainer.SetBackgroundSource(container.BackgroundImage, context); // Keep track of ContainerStyle.ForegroundColors before Container is rendered var parentRenderArgs = context.RenderArgs; var elementRenderArgs = new AdaptiveRenderArgs(parentRenderArgs); Grid uiOuterContainer = new Grid(); uiOuterContainer.Children.Add(uiContainer); Border border = new Border(); border.Child = uiOuterContainer; RendererUtil.ApplyVerticalContentAlignment(uiContainer, container); RendererUtil.ApplyIsVisible(border, container); uiContainer.MinHeight = container.PixelMinHeight; bool inheritsStyleFromParent = !container.Style.HasValue; bool hasPadding = false; if (!inheritsStyleFromParent) { hasPadding = ApplyPadding(border, uiOuterContainer, container, parentRenderArgs, context); // Apply background color ContainerStyleConfig containerStyle = context.Config.ContainerStyles.GetContainerStyleConfig(container.Style); border.Background = context.GetColorBrush(containerStyle.BackgroundColor); elementRenderArgs.ForegroundColors = containerStyle.ForegroundColors; } // Modify context outer parent style so padding necessity can be determined elementRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : container.Style.Value; elementRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding); context.RenderArgs = elementRenderArgs; AddContainerElements(uiContainer, container.Items, context); // Revert context's value to that of outside the Container context.RenderArgs = parentRenderArgs; return(RendererUtil.ApplySelectAction(border, container, context)); }
public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderContext 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); if (input.InlineAction != null) { if (context.Config.Actions.ShowCard.ActionMode == ShowCardActionMode.Inline && input.InlineAction.GetType() == typeof(AdaptiveShowCardAction)) { context.Warnings.Add(new AdaptiveWarning(-1, "Inline ShowCard not supported for InlineAction")); } else { if (context.Config.SupportsInteractivity && context.ActionHandlers.IsSupported(input.InlineAction.GetType())) { return(AdaptiveTextInputRenderer.RenderInlineAction(input, context, textBox)); } } } return(textBox); } else { var textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; return(context.Render(textBlock)); } }
public static FrameworkElement RenderSelectAction(this AdaptiveRenderContext context, AdaptiveAction selectAction, FrameworkElement uiElement) { if (context.Config.SupportsInteractivity) { context.IsRenderingSelectAction = true; var uiButton = (Button)context.Render(selectAction); context.IsRenderingSelectAction = false; // Stretch both the button and button's content to avoid empty spaces uiButton.HorizontalAlignment = HorizontalAlignment.Stretch; uiButton.HorizontalContentAlignment = HorizontalAlignment.Stretch; // Adopt the child element's background to parent and set the child's background // to be transparent in order for button's on mouse hover color to work properly if (uiElement is Panel p) { uiButton.Background = p.Background; p.Background = new SolidColorBrush(Colors.Transparent); } else { uiButton.Background = new SolidColorBrush(Colors.Transparent); } uiButton.BorderThickness = new Thickness(0); uiButton.Content = uiElement; uiButton.Style = context.GetStyle("Adaptive.Action.Tap"); // Handle ShowCard if (selectAction is AdaptiveShowCardAction showCardAction) { var actionsConfig = context.Config.Actions; bool isInline = (actionsConfig.ShowCard.ActionMode == ShowCardActionMode.Inline); if (isInline && context.CardDepth == 1) { FrameworkElement uiShowCardContainer = showCardAction.CreateShowCard(context, actionsConfig); // Add to the list of show cards in context context.ActionShowCards.Add(new Tuple <FrameworkElement, Button>(uiShowCardContainer, uiButton)); } } return(uiButton); } return(uiElement); }
public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderContext context) { if (context.Config.SupportsInteractivity) { var textBox = new TextBox() { 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.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 { AdaptiveContainer container = AdaptiveTypedElementConverter.CreateElement <AdaptiveContainer>(); container.Spacing = input.Spacing; container.Separator = input.Separator; AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>(); textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder; container.Items.Add(textBlock); if (input.Value != null) { textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>(); textBlock.Text = input.Value; textBlock.Color = AdaptiveTextColor.Accent; textBlock.Wrap = true; container.Items.Add(textBlock); } return(context.Render(container)); } }
public static FrameworkElement Render(AdaptiveActionSet actionSet, AdaptiveRenderContext context) { var outerActionSet = new Grid(); if (!context.Config.SupportsInteractivity) { return(outerActionSet); } outerActionSet.Style = context.GetStyle("Adaptive.Container"); // Keep track of ContainerStyle.ForegroundColors before Container is rendered AdaptiveRenderArgs parentRenderArgs = context.RenderArgs; AdaptiveRenderArgs elementRenderArgs = new AdaptiveRenderArgs(parentRenderArgs); AddRenderedActions(outerActionSet, actionSet.Actions, context, actionSet.InternalID); return(outerActionSet); }
public static FrameworkElement Render(AdaptiveToggleInput input, AdaptiveRenderContext context) { var uiToggle = new CheckBox(); AdaptiveChoiceSetRenderer.SetContent(uiToggle, input.Title, input.Wrap); uiToggle.Foreground = context.GetColorBrush(context.Config.ContainerStyles.Default.ForegroundColors.Default.Default); uiToggle.SetState(input.Value == (input.ValueOn ?? "true")); uiToggle.Style = context.GetStyle($"Adaptive.Input.Toggle"); uiToggle.SetContext(input); context.InputBindings.Add(input.Id, () => uiToggle.GetState() == true ? input.ValueOn ?? "true" : input.ValueOff ?? "false"); if (!input.IsVisible) { uiToggle.Visibility = Visibility.Collapsed; } return(uiToggle); }
public static FrameworkElement Render(AdaptiveTimeInput input, AdaptiveRenderContext context) { var textBox = new TextBox() { Text = input.Value }; textBox.SetPlaceholder(input.Placeholder); textBox.Style = context.GetStyle("Adaptive.Input.Text.Time"); textBox.SetContext(input); context.InputBindings.Add(input.Id, () => textBox.Text); if (!input.IsVisible) { textBox.Visibility = Visibility.Collapsed; } return(textBox); }
private static Inline FormatInlineTextRun(AdaptiveTextRun textRun, AdaptiveRenderContext context) { // Handle Date/Time parsing string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang); Span uiInlineElement = new Span(); uiInlineElement.Inlines.Add(text); uiInlineElement.Style = context.GetStyle($"Adaptive.{textRun.Type}"); uiInlineElement.FontFamily = new FontFamily(context.Config.GetFontFamily(textRun.FontStyle)); uiInlineElement.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontStyle, textRun.Weight)); uiInlineElement.FontSize = context.Config.GetFontSize(textRun.FontStyle, textRun.Size); uiInlineElement.SetColor(textRun.Color, textRun.IsSubtle, context); return(uiInlineElement); }
private static TextBlock CreateControl(AdaptiveRichTextBlock richTB, AdaptiveRenderContext context) { TextBlock uiTextBlock = new TextBlock(); uiTextBlock.Style = context.GetStyle($"Adaptive.{richTB.Type}"); uiTextBlock.TextWrapping = richTB.Wrap ? TextWrapping.Wrap : TextWrapping.NoWrap; uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (richTB.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.TextAlignment alignment; if (Enum.TryParse <System.Windows.TextAlignment>(richTB.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.TextAlignment = alignment; } } return(uiTextBlock); }
public static FrameworkElement RenderSelectAction(this AdaptiveRenderContext context, AdaptiveAction selectAction, FrameworkElement uiElement) { if (context.Config.SupportsInteractivity) { // SelectAction doesn't allow showCard actions if (selectAction is AdaptiveShowCardAction) { context.Warnings.Add(new AdaptiveWarning(-1, "Inline ShowCard not supported for SelectAction")); return(uiElement); } context.IsRenderingSelectAction = true; var uiButton = (Button)context.Render(selectAction); context.IsRenderingSelectAction = false; // Stretch both the button and button's content to avoid empty spaces uiButton.HorizontalAlignment = HorizontalAlignment.Stretch; uiButton.HorizontalContentAlignment = HorizontalAlignment.Stretch; // Adopt the child element's background to parent and set the child's background // to be transparent in order for button's on mouse hover color to work properly if (uiElement is Panel p) { uiButton.Background = p.Background; p.Background = new SolidColorBrush(Colors.Transparent); } else { uiButton.Background = new SolidColorBrush(Colors.Transparent); } uiButton.BorderThickness = new Thickness(0); uiButton.Content = uiElement; uiButton.Style = context.GetStyle("Adaptive.Action.Tap"); return(uiButton); } return(uiElement); }
public static FrameworkElement Render(AdaptiveImageSet imageSet, AdaptiveRenderContext context) { var uiImageSet = new ListBox(); uiImageSet.BorderThickness = new Thickness(0); uiImageSet.Background = new SolidColorBrush(Colors.Transparent); 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; uiImageSet.Style = context.GetStyle("Adaptive.ImageSet"); foreach (var image in imageSet.Images) { // Use the imageSize in imageSet for all images if present if (imageSet.ImageSize != AdaptiveImageSize.Auto) { image.Size = imageSet.ImageSize; } else if (image.Size == AdaptiveImageSize.Auto) { image.Size = context.Config.ImageSet.ImageSize; } var uiImage = context.Render(image); uiImageSet.Add(uiImage); } if (!imageSet.IsVisible) { uiImageSet.Visibility = Visibility.Collapsed; } return(uiImageSet); }
public static FrameworkElement Render(AdaptiveContainer container, AdaptiveRenderContext 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) { return(context.RenderSelectAction(container.SelectAction, uiContainer)); } Grid uiOuterContainer = new Grid(); uiOuterContainer.Background = context.GetColorBrush(containerStyle.BackgroundColor); uiOuterContainer.Children.Add(uiContainer); Border border = new Border(); border.Child = uiOuterContainer; return(border); }
/// <summary> /// Adds spacing as a grid element to the container /// </summary> /// <param name="context">Context</param> /// <param name="element">Element to render spacing for</param> /// <param name="uiContainer">Container of rendered elements</param> /// <returns>Spacing grid</returns> public static Grid AddSpacing(AdaptiveRenderContext context, AdaptiveElement element, Grid uiContainer) { if (element.Spacing == AdaptiveSpacing.None) { return(null); } var uiSpa = new Grid(); uiSpa.Style = context.GetStyle($"Adaptive.Spacing"); int spacing = context.Config.GetSpacing(element.Spacing); uiSpa.SetHeight(spacing); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiSpa, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiSpa); return(uiSpa); }
public static FrameworkElement Render(AdaptiveColumn column, AdaptiveRenderContext context) { var uiContainer = new Grid(); uiContainer.Style = context.GetStyle("Adaptive.Column"); uiContainer.SetBackgroundSource(column.BackgroundImage, context); AdaptiveContainerRenderer.AddContainerElements(uiContainer, column.Items, context); if (column.SelectAction != null) { return(context.RenderSelectAction(column.SelectAction, uiContainer)); } switch (column.VerticalContentAlignment) { case AdaptiveVerticalContentAlignment.Center: uiContainer.VerticalAlignment = VerticalAlignment.Center; break; case AdaptiveVerticalContentAlignment.Bottom: uiContainer.VerticalAlignment = VerticalAlignment.Bottom; break; case AdaptiveVerticalContentAlignment.Top: default: break; } if (!column.IsVisible) { uiContainer.Visibility = Visibility.Collapsed; } return(uiContainer); }
public static FrameworkElement CreateShowCard(this AdaptiveShowCardAction showCardAction, AdaptiveRenderContext context, ActionsConfig actionsConfig) { Grid uiShowCardContainer = new Grid(); uiShowCardContainer.Style = context.GetStyle("Adaptive.Actions.ShowCard"); uiShowCardContainer.DataContext = showCardAction; uiShowCardContainer.Margin = new Thickness(0, actionsConfig.ShowCard.InlineTopMargin, 0, 0); uiShowCardContainer.Visibility = Visibility.Collapsed; // render the card var uiShowCardWrapper = (Grid)context.Render(showCardAction.Card); uiShowCardWrapper.Background = context.GetColorBrush("Transparent"); uiShowCardWrapper.DataContext = showCardAction; // Remove the card padding var innerCard = (Grid)uiShowCardWrapper.Children[0]; innerCard.Margin = new Thickness(0); uiShowCardContainer.Children.Add(uiShowCardWrapper); return(uiShowCardContainer); }
public static FrameworkElement Render(AdaptiveColumnSet columnSet, AdaptiveRenderContext context) { var uiColumnSet = new Grid(); uiColumnSet.Style = context.GetStyle($"Adaptive.{columnSet.Type}"); // Keep track of ContainerStyle.ForegroundColors before Container is rendered var parentRenderArgs = context.RenderArgs; // This is the renderArgs that will be the base for all the columns renderArgs var childrenRenderArgs = new AdaptiveRenderArgs(parentRenderArgs); Border border = new Border(); border.Child = uiColumnSet; bool inheritsStyleFromParent = !columnSet.Style.HasValue; bool hasPadding = false; if (!inheritsStyleFromParent) { hasPadding = AdaptiveContainerRenderer.ApplyPadding(border, uiColumnSet, columnSet, parentRenderArgs, context); // Apply background color var columnSetStyle = context.Config.ContainerStyles.GetContainerStyleConfig(columnSet.Style); border.Background = context.GetColorBrush(columnSetStyle.BackgroundColor); childrenRenderArgs.ForegroundColors = columnSetStyle.ForegroundColors; } childrenRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : columnSet.Style.Value; for (int i = 0; i < columnSet.Columns.Count; ++i) { AdaptiveColumn column = columnSet.Columns[i]; var childRenderArgs = new AdaptiveRenderArgs(childrenRenderArgs); // Reset up and down bleed for columns as that behaviour shouldn't be changed childRenderArgs.BleedDirection |= (BleedDirection.BleedUp | BleedDirection.BleedDown); if (i != 0) { // Only the first column can bleed to the left childRenderArgs.BleedDirection &= ~BleedDirection.BleedLeft; } if (i != columnSet.Columns.Count - 1) { // Only the last column can bleed to the right childRenderArgs.BleedDirection &= ~BleedDirection.BleedRight; } context.RenderArgs = childRenderArgs; FrameworkElement uiContainer = context.Render(column); // If the column couldn't be rendered and the fallback is 'drop' if (uiContainer != null) { TagContent tag = null; // Add vertical Separator if (uiColumnSet.ColumnDefinitions.Count > 0 && (column.Separator || column.Spacing != AdaptiveSpacing.None)) { var uiSep = new Grid(); uiSep.Style = context.GetStyle($"Adaptive.VerticalSeparator"); uiSep.VerticalAlignment = VerticalAlignment.Stretch; int spacing = context.Config.GetSpacing(column.Spacing); uiSep.Margin = new Thickness(spacing / 2.0, 0, spacing / 2.0, 0); uiSep.Width = context.Config.Separator.LineThickness; if (column.Separator && context.Config.Separator.LineColor != null) { uiSep.Background = context.GetColorBrush(context.Config.Separator.LineColor); } tag = new TagContent(uiSep, uiColumnSet); uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); Grid.SetColumn(uiSep, uiColumnSet.ColumnDefinitions.Count - 1); uiColumnSet.Children.Add(uiSep); } else { tag = new TagContent(null, uiColumnSet); } // 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 ColumnDefinition columnDefinition = null; if (width == null || width == AdaptiveColumnWidth.Stretch.ToLower()) { columnDefinition = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }; } else if (width == AdaptiveColumnWidth.Auto.ToLower()) { columnDefinition = new ColumnDefinition() { Width = GridLength.Auto }; } else { if (double.TryParse(width, out double val) && val >= 0) { // Weighted proportion (number only) columnDefinition = new ColumnDefinition() { Width = new GridLength(val, GridUnitType.Star) }; } else if (width.EndsWith("px") && double.TryParse(width.Substring(0, width.Length - 2), out double pxVal) && pxVal >= 0) { // Exact pixel (number followed by "px") columnDefinition = new ColumnDefinition() { Width = new GridLength((int)pxVal, GridUnitType.Pixel) }; } else { columnDefinition = new ColumnDefinition() { Width = GridLength.Auto }; } } // Store the column definition in the tag so we can toggle the visibility later tag.ColumnDefinition = columnDefinition; tag.ViewIndex = uiColumnSet.ColumnDefinitions.Count; uiColumnSet.ColumnDefinitions.Add(columnDefinition); uiContainer.Tag = tag; Grid.SetColumn(uiContainer, uiColumnSet.ColumnDefinitions.Count - 1); uiColumnSet.Children.Add(uiContainer); context.SetVisibility(uiContainer, column.IsVisible, tag); } } context.ResetSeparatorVisibilityInsideContainer(uiColumnSet); // Revert context's value to that of outside the Container context.RenderArgs = parentRenderArgs; uiColumnSet.MinHeight = columnSet.PixelMinHeight; return(RendererUtil.ApplySelectAction(border, columnSet, context)); }
public static Button CreateActionButton(AdaptiveAction action, AdaptiveRenderContext context) { var uiButton = new Button { Style = context.GetStyle($"Adaptive.{action.Type}"), }; if (action.Sentiment == AdaptiveSentiment.Positive || action.Sentiment == AdaptiveSentiment.Destructive) { Style sentimentStyle = context.GetStyle($"Adaptive.{action.Type}.{action.Sentiment}"); if (sentimentStyle == null) { if (action.Sentiment == AdaptiveSentiment.Positive) { sentimentStyle = context.GetStyle("PositiveActionDefaultStyle"); } else if (action.Sentiment == AdaptiveSentiment.Destructive) { sentimentStyle = context.GetStyle("DestructiveActionDefaultStyle"); } } uiButton.Style = sentimentStyle; } var contentStackPanel = new StackPanel(); if (!context.IsRenderingSelectAction) { // Only apply padding for normal card actions uiButton.Padding = new Thickness(6, 4, 6, 4); } else { // Remove any extra spacing for selectAction uiButton.Padding = new Thickness(0, 0, 0, 0); contentStackPanel.Margin = new Thickness(0, 0, 0, 0); } uiButton.Content = contentStackPanel; FrameworkElement uiIcon = null; var uiTitle = new TextBlock { Text = action.Title, FontSize = context.Config.GetFontSize(AdaptiveFontStyle.Default, AdaptiveTextSize.Default), Style = context.GetStyle($"Adaptive.Action.Title") }; if (action.IconUrl != null) { var actionsConfig = context.Config.Actions; var image = new AdaptiveImage(action.IconUrl) { HorizontalAlignment = AdaptiveHorizontalAlignment.Center }; uiIcon = AdaptiveImageRenderer.Render(image, context); if (actionsConfig.IconPlacement == IconPlacement.AboveTitle) { contentStackPanel.Orientation = Orientation.Vertical; uiIcon.Height = (double)actionsConfig.IconSize; } else { contentStackPanel.Orientation = Orientation.Horizontal; //Size the image to the textblock, wait until layout is complete (loaded event) uiIcon.Loaded += (sender, e) => { uiIcon.Height = uiTitle.ActualHeight; }; } contentStackPanel.Children.Add(uiIcon); // Add spacing for the icon for horizontal actions if (actionsConfig.IconPlacement == IconPlacement.LeftOfTitle) { int spacing = context.Config.GetSpacing(AdaptiveSpacing.Default); var uiSep = new Grid { Style = context.GetStyle($"Adaptive.VerticalSeparator"), VerticalAlignment = VerticalAlignment.Stretch, Width = spacing, }; contentStackPanel.Children.Add(uiSep); } } contentStackPanel.Children.Add(uiTitle); string name = context.GetType().Name.Replace("Action", String.Empty); return(uiButton); }
public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context) { var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>(); 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.AdaptiveChoiceSetInput.ComboBox"); uiComboBox.DataContext = input; var uiChoices = new StackPanel(); uiChoices.DataContext = input; uiChoices.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput"); foreach (var choice in input.Choices) { if (input.IsMultiSelect == true) { var uiCheckbox = new CheckBox(); SetContent(uiCheckbox, choice.Title, input.Wrap); uiCheckbox.IsChecked = chosen.Contains(choice.Value); uiCheckbox.DataContext = choice; uiCheckbox.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox"); uiChoices.Children.Add(uiCheckbox); } else { if (input.Style == AdaptiveChoiceInputStyle.Compact) { var uiComboItem = new ComboBoxItem(); uiComboItem.HorizontalAlignment = HorizontalAlignment.Stretch; uiComboItem.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem"); TextBlock content = SetContent(uiComboItem, choice.Title, input.Wrap); // The content TextBlock is binded to the width of the comboBox container if (input.Wrap && content != null) { BindingOperations.SetBinding(content, TextBlock.MaxWidthProperty, new Binding("ActualWidth") { Source = uiComboBox }); } uiComboItem.DataContext = choice; uiComboBox.Items.Add(uiComboItem); // If multiple values are specified, no option is selected if (chosen.Contains(choice.Value) && chosen.Count == 1) { uiComboBox.SelectedItem = uiComboItem; } } else { var uiRadio = new RadioButton(); SetContent(uiRadio, choice.Title, input.Wrap); // When isMultiSelect is false, only 1 specified value is accepted. // Otherwise, don't set any option if (chosen.Count == 1) { uiRadio.IsChecked = chosen.Contains(choice.Value); } uiRadio.GroupName = input.Id; uiRadio.DataContext = choice; uiRadio.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio"); uiChoices.Children.Add(uiRadio); } } } context.InputBindings.Add(input.Id, () => { if (input.IsMultiSelect == true) { string values = string.Empty; foreach (var item in uiChoices.Children) { CheckBox checkBox = (CheckBox)item; AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice; if (checkBox.IsChecked == true) { values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value; } } return(values); } else { if (input.Style == AdaptiveChoiceInputStyle.Compact) { ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem; if (item != null) { AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice; return(adaptiveChoice.Value); } return(null); } else { foreach (var item in uiChoices.Children) { RadioButton radioBox = (RadioButton)item; AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice; if (radioBox.IsChecked == true) { return(adaptiveChoice.Value); } } return(null); } } }); if (!input.IsMultiSelect && input.Style == AdaptiveChoiceInputStyle.Compact) { Grid.SetRow(uiComboBox, 1); uiGrid.Children.Add(uiComboBox); return(uiGrid); } else { Grid.SetRow(uiChoices, 1); uiGrid.Children.Add(uiChoices); return(uiGrid); } }
public static FrameworkElement Render(AdaptiveColumnSet columnSet, AdaptiveRenderContext 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 != AdaptiveSpacing.None) { var uiSep = new Grid(); uiSep.Style = context.GetStyle($"Adaptive.VerticalSeparator"); uiSep.VerticalAlignment = VerticalAlignment.Stretch; int spacing = context.Config.GetSpacing(column.Spacing); uiSep.Margin = new Thickness(spacing / 2.0, 0, spacing / 2.0, 0); uiSep.Width = context.Config.Separator.LineThickness; if (column.Separator && context.Config.Separator.LineColor != null) { uiSep.Background = context.GetColorBrush(context.Config.Separator.LineColor); } 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 == AdaptiveColumnWidth.Stretch.ToLower()) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); } else if (width == AdaptiveColumnWidth.Auto.ToLower()) { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } else { if (double.TryParse(width, out double val) && val >= 0) { // Weighted proportion (number only) uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(val, GridUnitType.Star) }); } else if (width.EndsWith("px") && double.TryParse(width.Substring(0, width.Length - 2), out double pxVal) && pxVal >= 0) { // Exact pixel (number followed by "px") uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength((int)pxVal, GridUnitType.Pixel) }); } else { uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } } Grid.SetColumn(uiContainer, uiColumnSet.ColumnDefinitions.Count - 1); uiColumnSet.Children.Add(uiContainer); } if (columnSet.SelectAction != null) { return(context.RenderSelectAction(columnSet.SelectAction, uiColumnSet)); } if (!columnSet.IsVisible) { uiColumnSet.Visibility = Visibility.Collapsed; } return(uiColumnSet); }
public static void AddRenderedActions(Grid uiContainer, IList <AdaptiveAction> actions, AdaptiveRenderContext context, AdaptiveInternalID actionSetId) { if (!context.Config.SupportsInteractivity) { return; } ActionsConfig actionsConfig = context.Config.Actions; int maxActions = actionsConfig.MaxActions; List <AdaptiveAction> actionsToProcess = GetActionsToProcess(actions, maxActions, context); if (actionsToProcess.Any()) { var uiActionBar = new UniformGrid(); if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { uiActionBar.Columns = actionsToProcess.Count(); } else { uiActionBar.Rows = actionsToProcess.Count(); } uiActionBar.HorizontalAlignment = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), actionsConfig.ActionAlignment.ToString()); uiActionBar.VerticalAlignment = VerticalAlignment.Bottom; uiActionBar.Style = context.GetStyle("Adaptive.Actions"); // For vertical, we want to subtract the top margin of the first button int topMargin = actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal ? context.Config.GetSpacing(actionsConfig.Spacing) : context.Config.GetSpacing(actionsConfig.Spacing) - actionsConfig.ButtonSpacing; uiActionBar.Margin = new Thickness(0, topMargin, 0, 0); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiActionBar); bool isInline = (actionsConfig.ShowCard.ActionMode == ShowCardActionMode.Inline); int iPos = 0; // See if all actions have icons, otherwise force the icon placement to the left IconPlacement oldConfigIconPlacement = actionsConfig.IconPlacement; bool allActionsHaveIcons = true; foreach (AdaptiveAction action in actionsToProcess) { if (string.IsNullOrEmpty(action.IconUrl)) { allActionsHaveIcons = false; break; } } if (!allActionsHaveIcons) { actionsConfig.IconPlacement = IconPlacement.LeftOfTitle; } // indicates showcard has not been seen if it's set false; meaningful only if it's used // when inline is supported bool hasSeenInlineShowCard = false; foreach (AdaptiveAction action in actionsToProcess) { // add actions var uiAction = context.Render(action) as Button; if (uiAction == null) { context.Warnings.Add(new AdaptiveWarning(-1, $"action failed to render" + $"and valid fallback wasn't present")); continue; } if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { if (uiActionBar.Children.Count > 0) // don't apply left margin to the first item { uiAction.Margin = new Thickness(actionsConfig.ButtonSpacing, 0, 0, 0); } } else { uiAction.Margin = new Thickness(0, actionsConfig.ButtonSpacing, 0, 0); } if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { Grid.SetColumn(uiAction, iPos++); } uiActionBar.Children.Add(uiAction); if (action is AdaptiveShowCardAction showCardAction && isInline) { if (actionSetId != null) { // the button's context is used as key for retrieving the corresponding showcard uiAction.SetContext(actionSetId); if (!hasSeenInlineShowCard) { // Define a new row to contain all the show cards uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); // it's first showcard of the peers, create a new list context.PeerShowCardsInActionSet[actionSetId] = new List <FrameworkElement>(); } hasSeenInlineShowCard = true; Grid uiShowCardContainer = new Grid(); uiShowCardContainer.Style = context.GetStyle("Adaptive.Actions.ShowCard"); uiShowCardContainer.DataContext = showCardAction; uiShowCardContainer.Visibility = Visibility.Collapsed; var padding = context.Config.Spacing.Padding; // set negative margin to expand the wrapper to the edge of outer most card uiShowCardContainer.Margin = new Thickness(-padding, actionsConfig.ShowCard.InlineTopMargin, -padding, -padding); var showCardStyleConfig = context.Config.ContainerStyles.GetContainerStyleConfig(actionsConfig.ShowCard.Style); uiShowCardContainer.Background = context.GetColorBrush(showCardStyleConfig.BackgroundColor); // render the card var uiShowCardWrapper = (Grid)context.Render(showCardAction.Card); uiShowCardWrapper.Background = context.GetColorBrush("Transparent"); uiShowCardWrapper.DataContext = showCardAction; uiShowCardContainer.Children.Add(uiShowCardWrapper); context.ActionShowCards.Add(uiAction, uiShowCardContainer); // added the rendered show card as a peer context.PeerShowCardsInActionSet[actionSetId].Add(uiShowCardContainer); // define where in the rows of the parent Grid the show card will occupy // and add it to the parent Grid.SetRow(uiShowCardContainer, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiShowCardContainer); } else { context.Warnings.Add(new AdaptiveWarning(-1, $"button's corresponding showCard" + $" couldn't be added since the action set the button belongs to has null as internal id")); } } } // Restore the iconPlacement for the context. actionsConfig.IconPlacement = oldConfigIconPlacement; } }
public static void AddActions(Grid uiContainer, IList <AdaptiveAction> actions, AdaptiveRenderContext context) { if (!context.Config.SupportsInteractivity) { return; } var actionsConfig = context.Config.Actions; var maxActions = actionsConfig.MaxActions; var actionsToProcess = actions .Take(maxActions).ToList(); if (actionsToProcess.Any()) { var uiActionBar = new UniformGrid(); if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { uiActionBar.Columns = actionsToProcess.Count(); } else { uiActionBar.Rows = actionsToProcess.Count(); } uiActionBar.HorizontalAlignment = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), actionsConfig.ActionAlignment.ToString()); uiActionBar.VerticalAlignment = VerticalAlignment.Bottom; uiActionBar.Style = context.GetStyle("Adaptive.Actions"); // For vertical, we want to subtract the top margin of the first button var topMargin = actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal ? context.Config.GetSpacing(actionsConfig.Spacing) : context.Config.GetSpacing(actionsConfig.Spacing) - actionsConfig.ButtonSpacing; uiActionBar.Margin = new Thickness(0, topMargin, 0, 0); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiActionBar); bool isInline = (actionsConfig.ShowCard.ActionMode == ShowCardActionMode.Inline); int iPos = 0; // See if all actions have icons, otherwise force the icon placement to the left var oldConfigIconPlacement = actionsConfig.IconPlacement; bool allActionsHaveIcons = true; foreach (var action in actionsToProcess) { if (string.IsNullOrEmpty(action.IconUrl)) { allActionsHaveIcons = false; break; } } if (!allActionsHaveIcons) { actionsConfig.IconPlacement = IconPlacement.LeftOfTitle; } foreach (var action in actionsToProcess) { // add actions var uiAction = (Button)context.Render(action); if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { if (uiActionBar.Children.Count > 0) // don't apply left margin to the first item { uiAction.Margin = new Thickness(actionsConfig.ButtonSpacing, 0, 0, 0); } } else { uiAction.Margin = new Thickness(0, actionsConfig.ButtonSpacing, 0, 0); } if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { Grid.SetColumn(uiAction, iPos++); } uiActionBar.Children.Add(uiAction); if (action is AdaptiveShowCardAction showCardAction) { // Only support 1 level of showCard if (isInline && context.CardDepth == 1) { Grid uiShowCardContainer = new Grid(); uiShowCardContainer.Style = context.GetStyle("Adaptive.Actions.ShowCard"); uiShowCardContainer.DataContext = showCardAction; uiShowCardContainer.Margin = new Thickness(0, actionsConfig.ShowCard.InlineTopMargin, 0, 0); uiShowCardContainer.Visibility = Visibility.Collapsed; // render the card var uiShowCardWrapper = (Grid)context.Render(showCardAction.Card); uiShowCardWrapper.Background = context.GetColorBrush("Transparent"); uiShowCardWrapper.DataContext = showCardAction; // Remove the card padding var innerCard = (Grid)uiShowCardWrapper.Children[0]; innerCard.Margin = new Thickness(0); uiShowCardContainer.Children.Add(uiShowCardWrapper); // Add to the list of show cards in context context.ActionShowCards.Add(uiAction, uiShowCardContainer); } } } // Restore the iconPlacement for the context. actionsConfig.IconPlacement = oldConfigIconPlacement; } }
public static FrameworkElement Render(AdaptiveFactSet factSet, AdaptiveRenderContext context) { 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 AdaptiveTextBlock() { 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, MaxWidth = context.Config.FactSet.Title.MaxWidth, Text = fact.Title }); uiTitle.Style = context.GetStyle("Adaptive.Fact.Title"); uiTitle.Margin = new Thickness(left: 0, top: 0, right: context.Config.FactSet.Spacing, bottom: 0); var uiValue = context.Render(new AdaptiveTextBlock() { 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, // MaxWidth is not applicable to the Value field of the Fact // so ignore it. Text = fact.Value }); uiValue.Style = context.GetStyle("Adaptive.Fact.Value"); 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); } if (!factSet.IsVisible) { uiFactSet.Visibility = Visibility.Collapsed; } return(uiFactSet); }