// For applying bleeding, we must know if the element has padding, so both properties are applied in the same method public static bool ApplyPadding(Border border, Grid uiElement, AdaptiveCollectionElement element, AdaptiveRenderArgs parentRenderArgs, AdaptiveRenderContext context) { bool canApplyPadding = false; // AdaptiveColumn inherits from AdaptiveContainer so only one check is required for both if (element is AdaptiveContainer container) { canApplyPadding = ((container.BackgroundImage != null) || (container.Style.HasValue && (container.Style != parentRenderArgs.ParentStyle))); } else if (element is AdaptiveColumnSet columnSet) { canApplyPadding = (columnSet.Style.HasValue && (columnSet.Style != parentRenderArgs.ParentStyle)); } int padding = context.Config.Spacing.Padding; if (canApplyPadding) { uiElement.Margin = new Thickness(padding); if (element.Bleed) { border.Margin = GetBleedMargin(parentRenderArgs, -padding); } } return(canApplyPadding); }
// For applying bleeding, we must know if the element has padding, so both properties are applied in the same method public static bool ApplyPadding(Border border, Grid uiElement, AdaptiveCollectionElement element, AdaptiveRenderArgs parentRenderArgs, AdaptiveRenderContext context) { bool canApplyPadding = false; // AdaptiveColumn inherits from AdaptiveContainer so only one check is required for both if (element is AdaptiveContainer container) { canApplyPadding = ((container.BackgroundImage != null) || (container.Style.HasValue && (container.Style != parentRenderArgs.ParentStyle))); } else if (element is AdaptiveColumnSet columnSet) { canApplyPadding = (columnSet.Style.HasValue && (columnSet.Style != parentRenderArgs.ParentStyle)); } int padding = context.Config.Spacing.Padding; if (canApplyPadding) { uiElement.Margin = new Thickness { Left = padding, Top = padding, Right = padding, Bottom = padding }; if (element.Bleed && context.RenderArgs.HasParentWithPadding) { // Columns have a special rendering behaviour, only the leftmost and rightmost columns must bleed if (element is AdaptiveColumn column) { if (parentRenderArgs.ColumnRelativePosition == ColumnPositionEnum.Begin) { border.Margin = new Thickness { Left = -padding }; } else if (parentRenderArgs.ColumnRelativePosition == ColumnPositionEnum.End) { border.Margin = new Thickness { Right = -padding }; } else if (parentRenderArgs.ColumnRelativePosition == ColumnPositionEnum.Only) { border.Margin = new Thickness { Left = -padding, Right = -padding }; } } else { border.Margin = new Thickness { Left = -padding, Right = -padding }; } } } return(canApplyPadding); }
public static void ApplyVerticalContentAlignment(FrameworkElement uiElement, AdaptiveCollectionElement element) { switch (element.VerticalContentAlignment) { case AdaptiveVerticalContentAlignment.Center: uiElement.VerticalAlignment = VerticalAlignment.Center; break; case AdaptiveVerticalContentAlignment.Bottom: uiElement.VerticalAlignment = VerticalAlignment.Bottom; break; case AdaptiveVerticalContentAlignment.Top: default: break; } }
// For applying bleeding, we must know if the element has padding, so both properties are applied in the same method public static bool ApplyPadding(Border border, Grid uiElement, AdaptiveCollectionElement element, AdaptiveRenderArgs parentRenderArgs, AdaptiveRenderContext context) { bool canApplyPadding = false; // AdaptiveColumn inherits from AdaptiveContainer so only one check is required for both if (element is AdaptiveContainer container) { canApplyPadding = ((container.BackgroundImage != null) || (container.Style.HasValue && (container.Style != parentRenderArgs.ParentStyle))); } else if (element is AdaptiveColumnSet columnSet) { canApplyPadding = (columnSet.Style.HasValue && (columnSet.Style != parentRenderArgs.ParentStyle)); } int padding = context.Config.Spacing.Padding; if (canApplyPadding) { uiElement.Margin = new Thickness { Left = padding, Top = padding, Right = padding, Bottom = padding }; if (element.Bleed) { int leftMargin = 0, rightMargin = 0; if (parentRenderArgs.BleedDirection == BleedDirection.Left || parentRenderArgs.BleedDirection == BleedDirection.Both) { leftMargin = -padding; } if (parentRenderArgs.BleedDirection == BleedDirection.Right || parentRenderArgs.BleedDirection == BleedDirection.Both) { rightMargin = -padding; } border.Margin = new Thickness { Left = leftMargin, Right = rightMargin }; } } return(canApplyPadding); }
public static void AddContainerElements(Grid uiContainer, IList <AdaptiveElement> elements, AdaptiveRenderContext context) { // Keeping track of the index so we don't have to call IndexOf function on every iteration int index = 0; foreach (var cardElement in elements) { if (index != 0) { // Only the first element can bleed to the top context.RenderArgs.BleedDirection &= ~BleedDirection.BleedUp; } if (index != elements.Count - 1) { // Only the last element can bleed to the bottom context.RenderArgs.BleedDirection &= ~BleedDirection.BleedDown; } index++; // each element has a row FrameworkElement uiElement = context.Render(cardElement); if (uiElement != null) { TagContent tag = null; Grid separator = null; if (cardElement.Separator && uiContainer.Children.Count > 0) { separator = AddSeparator(context, cardElement, uiContainer); } else if (uiContainer.Children.Count > 0) { separator = AddSpacing(context, cardElement, uiContainer); } tag = new TagContent(separator, uiContainer); uiElement.Tag = tag; // Sets the minHeight property for Container and ColumnSet if (cardElement.Type == "Container" || cardElement.Type == "ColumnSet") { AdaptiveCollectionElement collectionElement = (AdaptiveCollectionElement)cardElement; uiElement.MinHeight = collectionElement.PixelMinHeight; } int rowDefinitionIndex = uiContainer.RowDefinitions.Count; RowDefinition rowDefinition = null; if (cardElement.Height != AdaptiveHeight.Stretch) { rowDefinition = new RowDefinition() { Height = GridLength.Auto }; uiContainer.RowDefinitions.Add(rowDefinition); Grid.SetRow(uiElement, rowDefinitionIndex); uiContainer.Children.Add(uiElement); // Row definition is stored in the tag for containers and elements that stretch // so when the elements are shown, the row can have it's original definition, // while when the element is hidden, the extra space is not reserved in the layout tag.RowDefinition = rowDefinition; tag.ViewIndex = rowDefinitionIndex; context.SetVisibility(uiElement, cardElement.IsVisible, tag); } else { rowDefinition = new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }; uiContainer.RowDefinitions.Add(rowDefinition); // Row definition is stored in the tag for containers and elements that stretch // so when the elements are shown, the row can have it's original definition, // while when the element is hidden, the extra space is not reserved in the layout tag.RowDefinition = rowDefinition; tag.ViewIndex = rowDefinitionIndex; if (cardElement.Type == "Container") { Grid.SetRow(uiElement, rowDefinitionIndex); uiContainer.Children.Add(uiElement); context.SetVisibility(uiElement, cardElement.IsVisible, tag); } else { StackPanel panel = new StackPanel(); if (!String.IsNullOrEmpty(cardElement.Id)) { panel.Name = cardElement.Id; } panel.Children.Add(uiElement); panel.Tag = tag; Grid.SetRow(panel, rowDefinitionIndex); uiContainer.Children.Add(panel); context.SetVisibility(panel, cardElement.IsVisible, tag); } } } } context.ResetSeparatorVisibilityInsideContainer(uiContainer); }
public static void AddContainerElements(Grid uiContainer, IList <AdaptiveElement> elements, AdaptiveRenderContext context) { foreach (var cardElement in elements) { // each element has a row FrameworkElement uiElement = context.Render(cardElement); if (uiElement != null) { if (cardElement.Separator && uiContainer.Children.Count > 0) { AddSeparator(context, cardElement, uiContainer); } else if (uiContainer.Children.Count > 0) { var spacing = context.Config.GetSpacing(cardElement.Spacing); Thickness renderedMargin = uiElement.Margin; uiElement.Margin = new Thickness(renderedMargin.Left, renderedMargin.Top + spacing, renderedMargin.Right, renderedMargin.Bottom); } if (cardElement.Type == "Container" || cardElement.Type == "ColumnSet") { AdaptiveCollectionElement collectionElement = (AdaptiveCollectionElement)cardElement; uiElement.MinHeight = collectionElement.PixelMinHeight; } if (cardElement.Height != AdaptiveHeight.Stretch) { uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiElement, uiContainer.RowDefinitions.Count - 1); RendererUtil.ApplyIsVisible(uiElement, cardElement); Grid.SetRow(uiElement, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiElement); } else { if (cardElement.Type == "Container") { RendererUtil.ApplyIsVisible(uiElement, cardElement); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); Grid.SetRow(uiElement, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiElement); } else { StackPanel panel = new StackPanel(); RendererUtil.ApplyIsVisible(panel, cardElement); if (!String.IsNullOrEmpty(cardElement.Id)) { panel.Name = cardElement.Id; } panel.Children.Add(uiElement); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); Grid.SetRow(panel, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(panel); } } } } }