public static FrameworkElement Render(AdaptiveImage image, AdaptiveRenderContext context) { var uiImage = new Image(); uiImage.SetSource(image.Url, context); uiImage.SetHorizontalAlignment(image.HorizontalAlignment); string style = $"Adaptive.{image.Type}"; if (image.Style == AdaptiveImageStyle.Person) { style += $".{image.Style}"; 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; } uiImage.Style = context.GetStyle(style); uiImage.SetImageProperties(image, context); if (image.SelectAction != null) { return(context.RenderSelectAction(image.SelectAction, uiImage)); } return(uiImage); }
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); } 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 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)); } switch (column.VerticalContentAlignment) { case AdaptiveVerticalContentAlignment.Center: uiContainer.VerticalAlignment = VerticalAlignment.Center; break; case AdaptiveVerticalContentAlignment.Bottom: uiContainer.VerticalAlignment = VerticalAlignment.Bottom; break; case AdaptiveVerticalContentAlignment.Top: default: break; } return(uiContainer); }
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"); uiContainer.SetBackgroundSource(container.BackgroundImage, context); // Keep track of ContainerStyle.ForegroundColors before Container is rendered var outerStyle = context.ForegroundColors; if (container.Style != null) { // Apply background color ContainerStyleConfig containerStyle = context.Config.ContainerStyles.GetContainerStyleConfig(container.Style); uiContainer.SetBackgroundColor(containerStyle.BackgroundColor, context); context.ForegroundColors = containerStyle.ForegroundColors; } 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; if (!container.IsVisible) { border.Visibility = Visibility.Collapsed; } // Revert context's value to that of outside the Container context.ForegroundColors = outerStyle; return(border); }
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"); uiContainer.SetBackgroundSource(container.BackgroundImage, context); 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; if (!container.IsVisible) { border.Visibility = Visibility.Collapsed; } return(border); }
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 ApplySelectAction(FrameworkElement uiElement, AdaptiveElement element, AdaptiveRenderContext context) { AdaptiveAction selectAction = null; if (element is AdaptiveCollectionElement) { selectAction = (element as AdaptiveCollectionElement).SelectAction; } else if (element is AdaptiveImage) { selectAction = (element as AdaptiveImage).SelectAction; } if (selectAction != null) { return(context.RenderSelectAction(selectAction, uiElement)); } return(uiElement); }
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 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; var elementRenderArgs = 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); elementRenderArgs.ForegroundColors = columnSetStyle.ForegroundColors; } elementRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : columnSet.Style.Value; elementRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding); for (int i = 0; i < columnSet.Columns.Count; ++i) { AdaptiveColumn column = columnSet.Columns[i]; var columnRenderArgs = new AdaptiveRenderArgs(elementRenderArgs); if (columnSet.Columns.Count == 1) { columnRenderArgs.ColumnRelativePosition = ColumnPositionEnum.Only; } else { if (i == 0) { columnRenderArgs.ColumnRelativePosition = ColumnPositionEnum.Begin; } else if (i == (columnSet.Columns.Count - 1)) { columnRenderArgs.ColumnRelativePosition = ColumnPositionEnum.End; } else { columnRenderArgs.ColumnRelativePosition = ColumnPositionEnum.Intermediate; } } context.RenderArgs = columnRenderArgs; 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, border)); } if (!columnSet.IsVisible) { uiColumnSet.Visibility = Visibility.Collapsed; } // Revert context's value to that of outside the Container context.RenderArgs = parentRenderArgs; return(border); }
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); if (column.SelectAction != null) { return(context.RenderSelectAction(column.SelectAction, border)); } 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; } // Revert context's value to that of outside the Column context.RenderArgs = parentRenderArgs; return(border); }
public static FrameworkElement Render(AdaptiveImage image, AdaptiveRenderContext context) { FrameworkElement uiBorder = null; var uiImage = new Image(); // Try to resolve the image URI Uri finalUri = context.Config.ResolveFinalAbsoluteUri(image.Url); if (finalUri == null) { return(uiImage); } uiImage.SetSource(image, finalUri, context); uiImage.SetHorizontalAlignment(image.HorizontalAlignment); string style = $"Adaptive.{image.Type}"; if (image.Style == AdaptiveImageStyle.Person) { style += $".{image.Style}"; 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"), 1.0)); mask.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#00ffffff"), 1.0)); uiImage.OpacityMask = mask; } uiImage.Style = context.GetStyle(style); if (image.PixelHeight == 0 && image.PixelWidth == 0) { uiImage.SetImageProperties(image, context); } // If we have a background color, we'll create a border for the background and put the image on top if (!string.IsNullOrEmpty(image.BackgroundColor)) { Color color = (Color)ColorConverter.ConvertFromString(image.BackgroundColor); if (color.A != 0) { uiBorder = new Border() { Background = new SolidColorBrush(color), Child = uiImage, Width = uiImage.Width, Height = uiImage.Height, HorizontalAlignment = uiImage.HorizontalAlignment, VerticalAlignment = uiImage.VerticalAlignment, OpacityMask = uiImage.OpacityMask }; } } if (image.SelectAction != null) { return(context.RenderSelectAction(image.SelectAction, uiBorder ?? uiImage)); } return(uiBorder ?? uiImage); }
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; if (!container.IsVisible) { border.Visibility = Visibility.Collapsed; } bool inheritsStyleFromParent = (container.Style == AdaptiveContainerStyle.None); 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; } switch (container.VerticalContentAlignment) { case AdaptiveVerticalContentAlignment.Center: uiContainer.VerticalAlignment = VerticalAlignment.Center; break; case AdaptiveVerticalContentAlignment.Bottom: uiContainer.VerticalAlignment = VerticalAlignment.Bottom; break; case AdaptiveVerticalContentAlignment.Top: default: break; } // Modify context outer parent style so padding necessity can be determined elementRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : container.Style; elementRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding); context.RenderArgs = elementRenderArgs; AddContainerElements(uiContainer, container.Items, context); if (container.SelectAction != null) { return(context.RenderSelectAction(container.SelectAction, border)); } // Revert context's value to that of outside the Container context.RenderArgs = parentRenderArgs; return(border); }
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 outerStyle = context.ForegroundColors; var parentContainerStyle = context.ParentStyle; if (column.Style != null) { AdaptiveContainerRenderer.ApplyPadding(uiContainer, column, parentContainerStyle, context); // Apply background color ContainerStyleConfig containerStyle = context.Config.ContainerStyles.GetContainerStyleConfig(column.Style); uiContainer.SetBackgroundColor(containerStyle.BackgroundColor, context); context.ForegroundColors = containerStyle.ForegroundColors; } AdaptiveContainerStyle containerContainerStyle = column.Style ?? parentContainerStyle; if (containerContainerStyle == AdaptiveContainerStyle.None) { containerContainerStyle = parentContainerStyle; } context.ParentStyle = containerContainerStyle; 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; } // Revert context's value to that of outside the Column context.ForegroundColors = outerStyle; context.ParentStyle = parentContainerStyle; return(uiContainer); }