示例#1
0
        public static FrameworkElement RenderAdaptiveCardWrapper(AdaptiveCard card, AdaptiveRenderContext context)
        {
            var outerGrid = new Grid();

            outerGrid.Style = context.GetStyle("Adaptive.Card");

            outerGrid.Background = context.GetColorBrush(context.Config.ContainerStyles.Default.BackgroundColor);

            outerGrid.SetBackgroundSource(card.BackgroundImage, context);

            var grid = new Grid();

            grid.Style  = context.GetStyle("Adaptive.InnerCard");
            grid.Margin = new Thickness(context.Config.Spacing.Padding);

            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });


            AdaptiveContainerRenderer.AddContainerElements(grid, card.Body, context);
            AdaptiveActionSetRenderer.AddActions(grid, card.Actions, context);

            outerGrid.Children.Add(grid);
            return(outerGrid);
        }
        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);
        }
示例#3
0
        public static FrameworkElement RenderAdaptiveCardWrapper(AdaptiveCard card, AdaptiveRenderContext context)
        {
            var outerGrid = new Grid();

            outerGrid.Style = context.GetStyle("Adaptive.Card");

            outerGrid.Background = context.GetColorBrush(context.Config.ContainerStyles.Default.BackgroundColor);
            outerGrid.SetBackgroundSource(card.BackgroundImage, context);

            if (context.CardRoot == null)
            {
                context.CardRoot = outerGrid;
            }

            // Reset the parent style
            context.RenderArgs.ParentStyle = AdaptiveContainerStyle.Default;

            var grid = new Grid();

            grid.Style  = context.GetStyle("Adaptive.InnerCard");
            grid.Margin = new Thickness(context.Config.Spacing.Padding);

            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });

            switch (card.VerticalContentAlignment)
            {
            case AdaptiveVerticalContentAlignment.Center:
                grid.VerticalAlignment = VerticalAlignment.Center;
                break;

            case AdaptiveVerticalContentAlignment.Bottom:
                grid.VerticalAlignment = VerticalAlignment.Bottom;
                break;

            case AdaptiveVerticalContentAlignment.Top:
            default:
                break;
            }

            outerGrid.MinHeight = card.PixelMinHeight;

            outerGrid.Children.Add(grid);

            AdaptiveContainerRenderer.AddContainerElements(grid, card.Body, context);
            AdaptiveActionSetRenderer.AddRenderedActions(grid, card.Actions, context);


            if (card.SelectAction != null)
            {
                var outerGridWithSelectAction = context.RenderSelectAction(card.SelectAction, outerGrid);

                return(outerGridWithSelectAction);
            }

            return(outerGrid);
        }
        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;
            // This is the renderArgs that will be passed down to the children
            var childRenderArgs = 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);

                childRenderArgs.ForegroundColors = containerStyle.ForegroundColors;
            }

            childRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : column.Style.Value;

            // If the column has no padding or has padding and doesn't bleed, then the children can bleed
            // to the side the column would have bled
            if (columnHasPadding)
            {
                childRenderArgs.BleedDirection = BleedDirection.Both;
            }

            // If either this column or an ancestor had padding, then the children will have an ancestor with padding
            childRenderArgs.HasParentWithPadding = (columnHasPadding || parentRenderArgs.HasParentWithPadding);
            context.RenderArgs = childRenderArgs;

            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(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));
        }
示例#6
0
        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(AdaptiveColumn adaptiveColumn, AdaptiveRenderContext context)
        {
            var uiContainer = new Grid();

            uiContainer.Style = context.GetStyle("Adaptive.Column");

            AdaptiveContainerRenderer.AddContainerElements(uiContainer, adaptiveColumn.Items, context);

            if (adaptiveColumn.SelectAction != null)
            {
                var uiButton = (Button)context.Render(adaptiveColumn.SelectAction);
                if (uiButton != null)
                {
                    uiButton.Content = uiContainer;
                    uiButton.Style   = context.GetStyle("Adaptive.Action.Tap");
                    return(uiButton);
                }
            }

            return(uiContainer);
        }
        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 FrameworkElement RenderAdaptiveCardWrapper(AdaptiveCard card, AdaptiveRenderContext context)
        {
            var outerGrid = new Grid();

            outerGrid.Style = context.GetStyle("Adaptive.Card");

            outerGrid.Background = context.GetColorBrush(context.Config.ContainerStyles.Default.BackgroundColor);
            outerGrid.SetBackgroundSource(card.BackgroundImage, context);

            if (context.CardRoot == null)
            {
                context.CardRoot = outerGrid;
            }

            // Reset the parent style
            context.RenderArgs.ParentStyle = AdaptiveContainerStyle.Default;

            var grid = new Grid();

            grid.Style  = context.GetStyle("Adaptive.InnerCard");
            grid.Margin = new Thickness(context.Config.Spacing.Padding);

            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });

            switch (card.VerticalContentAlignment)
            {
            case AdaptiveVerticalContentAlignment.Center:
                grid.VerticalAlignment = VerticalAlignment.Center;
                break;

            case AdaptiveVerticalContentAlignment.Bottom:
                grid.VerticalAlignment = VerticalAlignment.Bottom;
                break;

            case AdaptiveVerticalContentAlignment.Top:
            default:
                break;
            }

            AdaptiveContainerRenderer.AddContainerElements(grid, card.Body, context);
            AdaptiveActionSetRenderer.AddActions(grid, card.Actions, context);

            // Only handle Action show cards for the main card
            if (context.CardDepth == 1)
            {
                // Define a new row to contain all the show cards
                if (context.ActionShowCards.Count > 0)
                {
                    grid.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = GridLength.Auto
                    });
                }

                foreach (var showCardTuple in context.ActionShowCards)
                {
                    var currentShowCard = showCardTuple.Value;
                    var uiButton        = showCardTuple.Key;

                    Grid.SetRow(currentShowCard, grid.RowDefinitions.Count - 1);
                    grid.Children.Add(currentShowCard);

                    // Assign on click function to all button elements
                    uiButton.Click += (sender, e) =>
                    {
                        bool isCardCollapsed = (currentShowCard.Visibility != Visibility.Visible);

                        // Collapse all the show cards
                        foreach (var t in context.ActionShowCards)
                        {
                            var showCard = t.Value;
                            showCard.Visibility = Visibility.Collapsed;
                        }

                        // If current card is previously collapsed, show it
                        if (isCardCollapsed)
                        {
                            currentShowCard.Visibility = Visibility.Visible;
                        }
                    };
                }
            }

            outerGrid.Children.Add(grid);

            if (card.SelectAction != null)
            {
                var outerGridWithSelectAction = context.RenderSelectAction(card.SelectAction, outerGrid);

                return(outerGridWithSelectAction);
            }

            return(outerGrid);
        }
示例#10
0
        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);
        }
示例#11
0
        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(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);
        }
示例#13
0
        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 outerStyle           = context.ForegroundColors;
            var parentContainerStyle = context.ParentStyle;

            if (columnSet.Style != null)
            {
                AdaptiveContainerRenderer.ApplyPadding(uiColumnSet, columnSet, parentContainerStyle, context);

                // Apply background color
                var columnSetStyle = context.Config.ContainerStyles.GetContainerStyleConfig(columnSet.Style);

                uiColumnSet.SetBackgroundColor(columnSetStyle.BackgroundColor, context);
                context.ForegroundColors = columnSetStyle.ForegroundColors;
            }

            AdaptiveContainerStyle columnSetContainerStyle = columnSet.Style ?? parentContainerStyle;

            if (columnSetContainerStyle == AdaptiveContainerStyle.None)
            {
                columnSetContainerStyle = parentContainerStyle;
            }
            context.ParentStyle = columnSetContainerStyle;

            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;
            }

            // Revert context's value to that of outside the Container
            context.ForegroundColors = outerStyle;
            context.ParentStyle      = parentContainerStyle;

            return(uiColumnSet);
        }