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 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;
            }
        }
Exemple #3
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;
            // 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);

                if (hasPadding)
                {
                    if (columnSet.Columns.Count == 1)
                    {
                        childRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding);
                        childRenderArgs.BleedDirection       = BleedDirection.Both;
                    }
                    else
                    {
                        if (i == 0)
                        {
                            childRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding);
                            childRenderArgs.BleedDirection       = BleedDirection.Left;
                        }
                        else if (i == (columnSet.Columns.Count - 1))
                        {
                            childRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding);
                            childRenderArgs.BleedDirection       = BleedDirection.Right;
                        }
                        else
                        {
                            childRenderArgs.BleedDirection = BleedDirection.None;
                        }
                    }
                }
                else
                {
                    if (columnSet.Columns.Count == 1)
                    {
                        childRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding);
                        childRenderArgs.BleedDirection       = parentRenderArgs.BleedDirection;
                    }
                    else
                    {
                        if (i == 0 &&
                            (childRenderArgs.BleedDirection == BleedDirection.Left || childRenderArgs.BleedDirection == BleedDirection.Both))
                        {
                            childRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding);
                            childRenderArgs.BleedDirection       = BleedDirection.Left;
                        }
                        else if (i == (columnSet.Columns.Count - 1) &&
                                 (childRenderArgs.BleedDirection == BleedDirection.Right || childRenderArgs.BleedDirection == BleedDirection.Both))
                        {
                            childRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding);
                            childRenderArgs.BleedDirection       = BleedDirection.Right;
                        }
                        else
                        {
                            childRenderArgs.BleedDirection = BleedDirection.None;
                        }
                    }
                }

                context.RenderArgs = childRenderArgs;

                FrameworkElement uiContainer = context.Render(column);

                TagContent tag = null;

                // Add vertical Separator
                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);
                        }

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

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

            if (hasPadding)
            {
                childRenderArgs.BleedDirection = BleedDirection.Both;
            }

            // Modify context outer parent style so padding necessity can be determined
            childRenderArgs.ParentStyle          = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : container.Style.Value;
            childRenderArgs.HasParentWithPadding = (hasPadding || parentRenderArgs.HasParentWithPadding);
            context.RenderArgs = childRenderArgs;

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

            // Revert context's value to that of outside the Container
            context.RenderArgs = parentRenderArgs;

            RendererUtil.ApplyIsVisible(uiColumnSet, columnSet);
            uiColumnSet.MinHeight = columnSet.PixelMinHeight;

            return(RendererUtil.ApplySelectAction(border, columnSet, context));
        }
Exemple #6
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);
        }
        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
                {
                    double val;
                    if (double.TryParse(width, out val))
                    {
                        uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = new GridLength(val, GridUnitType.Star)
                        });
                    }
                    else
                    {
                        uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = GridLength.Auto
                        });
                    }
                }

                Grid.SetColumn(uiContainer, uiColumnSet.ColumnDefinitions.Count - 1);
                uiColumnSet.Children.Add(uiContainer);
            }

            if (columnSet.SelectAction != null)
            {
                return(context.RenderSelectAction(columnSet.SelectAction, uiColumnSet));
            }
            return(uiColumnSet);
        }
        public static void AddActions(Grid uiContainer, IList <AdaptiveAction> actions, AdaptiveRenderContext context)
        {
            var maxActions       = context.Config.Actions.MaxActions;
            var actionsToProcess = actions
                                   .Take(maxActions).ToList();

            if (actionsToProcess.Any())
            {
                var uiActionBar = new UniformGrid();

                if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal)
                {
                    uiActionBar.Columns = actionsToProcess.Count();
                }
                else
                {
                    uiActionBar.Rows = actionsToProcess.Count();
                }

                uiActionBar.HorizontalAlignment = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), context.Config.Actions.ActionAlignment.ToString());
                uiActionBar.VerticalAlignment   = VerticalAlignment.Bottom;
                uiActionBar.Style  = context.GetStyle("Adaptive.Actions");
                uiActionBar.Margin = new Thickness(0, context.Config.GetSpacing(AdaptiveSpacing.Default), 0, 0);

                uiContainer.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1);
                uiContainer.Children.Add(uiActionBar);

                bool isInline = (context.Config.Actions.ShowCard.ActionMode == ShowCardActionMode.Inline);

                if (isInline && actionsToProcess.Any(a => a is AdaptiveShowCardAction))
                {
                    uiContainer.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = GridLength.Auto
                    });
                }

                int iPos = 0;
                List <FrameworkElement> actionBarCards = new List <FrameworkElement>();
                foreach (var action in actionsToProcess)
                {
                    // add actions
                    var uiAction = (Button)context.Render(action);
                    if (uiAction != null)
                    {
                        if (uiActionBar.Children.Count > 0)
                        {
                            if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal)
                            {
                                uiAction.Margin = new Thickness(context.Config.Actions.ButtonSpacing, 0, 0, 0);
                            }
                            else
                            {
                                uiAction.Margin = new Thickness(0, context.Config.Actions.ButtonSpacing, 0, 0);
                            }
                        }

                        if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal)
                        {
                            Grid.SetColumn(uiAction, iPos++);
                        }

                        uiActionBar.Children.Add(uiAction);

                        if (action is AdaptiveShowCardAction)
                        {
                            AdaptiveShowCardAction adaptiveShowCardAction = (AdaptiveShowCardAction)action;
                            if (isInline)
                            {
                                Grid uiShowCardContainer = new Grid();
                                uiShowCardContainer.Style       = context.GetStyle("Adaptive.Actions.ShowCard");
                                uiShowCardContainer.DataContext = adaptiveShowCardAction;
                                uiShowCardContainer.Margin      = new Thickness(0, context.Config.Actions.ShowCard.InlineTopMargin, 0, 0);
                                uiShowCardContainer.Visibility  = Visibility.Collapsed;

                                // render the card
                                var uiShowCard = context.Render(adaptiveShowCardAction.Card);
                                ((Grid)uiShowCard).Background = context.GetColorBrush("Transparent");
                                uiShowCard.DataContext        = adaptiveShowCardAction;
                                uiShowCardContainer.Children.Add(uiShowCard);

                                actionBarCards.Add(uiShowCardContainer);
                                Grid.SetRow(uiShowCardContainer, uiContainer.RowDefinitions.Count - 1);
                                uiContainer.Children.Add(uiShowCardContainer);

                                uiAction.Click += (sender, e) =>
                                {
                                    bool showCard = (uiShowCardContainer.Visibility != Visibility.Visible);
                                    foreach (var actionBarCard in actionBarCards)
                                    {
                                        actionBarCard.Visibility = Visibility.Collapsed;
                                    }
                                    if (showCard)
                                    {
                                        uiShowCardContainer.Visibility = Visibility.Visible;
                                    }
                                };
                            }
                        }
                    }
                }
            }
        }
Exemple #9
0
 public static void SetBorderColor(this Button view, string color, AdaptiveRenderContext context)
 {
     view.BorderBrush = context.GetColorBrush(color);
 }
Exemple #10
0
 public static void SetBackgroundColor(this Button panel, string color, AdaptiveRenderContext context)
 {
     panel.Background = context.GetColorBrush(color);
 }
Exemple #11
0
 public static void SetColor(this TextBlock textBlock, string color, AdaptiveRenderContext context)
 {
     textBlock.Foreground = context.GetColorBrush(color);
 }