private static AdaptiveStackPanel GenerateSubgroup( AdaptiveSubgroup subgroup, bool isFirstGroup, double topMarginOffset, Thickness externalMargin) { AdaptiveStackPanel sp = new AdaptiveStackPanel(); GenerateItems( children: subgroup.Children, container: sp.Children, isFirstGroup: isFirstGroup, isInsideGroup: true, topMarginOffset: topMarginOffset, externalMargin: externalMargin); // If we are in the first group, we apply the top margin to the subgroup // because some of the items might have negative margins if (isFirstGroup) { sp.Margin = new Thickness(0, externalMargin.Top, 0, 0); } return(sp); }
public static UIElement Render(AdaptiveContainer adaptiveContainer, Thickness externalMargin) { AdaptiveStackPanel answer = new AdaptiveStackPanel() { IsTopLevel = true }; VerticalAlignment valignment; switch (adaptiveContainer.HintTextStacking) { case HintTextStacking.Bottom: valignment = VerticalAlignment.Bottom; break; case HintTextStacking.Center: valignment = VerticalAlignment.Center; break; default: valignment = VerticalAlignment.Top; break; } answer.VerticalAlignment = valignment; double topMarginOffset = externalMargin.Top; GenerateItems( children: adaptiveContainer.Children, container: answer.Children, isFirstGroup: true, isInsideGroup: false, topMarginOffset: 0, externalMargin: externalMargin); // If the first child is a group/subgroup, we set the top margin to 0 if (answer.Children.FirstOrDefault() is AdaptiveStackPanel || answer.Children.FirstOrDefault() is AdaptiveGrid) { externalMargin.Top = 0; } answer.Margin = externalMargin; return(answer); }
private static FrameworkElement GenerateGroup( AdaptiveGroup group, bool isFirstGroup, bool needsImageMargin, Thickness externalMargin) { if (group.Subgroups.Count == 0) { return(null); } double topMarginOffset = 0; if (!isFirstGroup) { topMarginOffset = GetSubgroupsTopMarginOffset(group.Subgroups); } if (needsImageMargin) { // Ensure that top margin will be at least the image margin, even though we haven't an image if (topMarginOffset < AdaptiveConstants.DefaultImageMargin) { topMarginOffset = AdaptiveConstants.DefaultImageMargin; } } Thickness groupMargin = new Thickness( 0, isFirstGroup ? 0.0 : AdaptiveConstants.DefaultGroupTopMargin, 0, 0); if (group.Subgroups.Count == 1) { AdaptiveStackPanel sp = GenerateSubgroup( subgroup: group.Subgroups[0], isFirstGroup: isFirstGroup, topMarginOffset: topMarginOffset, externalMargin: externalMargin); sp.Margin = new Thickness( sp.Margin.Left, sp.Margin.Top + groupMargin.Top, sp.Margin.Right, sp.Margin.Bottom); if (group.ActionId != null) { sp.Background = GetActionBackgroundBrush(); } return(sp); } else { Grid g = new AdaptiveGrid() { Margin = groupMargin }; // Get the calculated weights int[] weights = CalculateWeights(group.Subgroups); for (int i = 0; i < group.Subgroups.Count; i++) { var subgroup = group.Subgroups[i]; int weight = weights[i]; //add column for the subgroup g.ColumnDefinitions.Add(new ColumnDefinition() { Width = weight == AdaptiveSubgroup.WEIGHT_AUTO ? GridLength.Auto : new GridLength(weight, GridUnitType.Star) }); //and create the subgroup visual var subgroupEl = GenerateSubgroup(subgroup, isFirstGroup, topMarginOffset, externalMargin); Grid.SetColumn(subgroupEl, g.ColumnDefinitions.Count - 1); //assign it to this column //set text stacking switch (subgroup.HintTextStacking) { case HintTextStacking.Bottom: subgroupEl.VerticalAlignment = VerticalAlignment.Bottom; break; case HintTextStacking.Center: subgroupEl.VerticalAlignment = VerticalAlignment.Center; break; } //and then add that subgroup visual to the group visual g.Children.Add(subgroupEl); //always add 8 pixel padding between columns (but not on the right, last, side) if (i != group.Subgroups.Count - 1) { g.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(8) }); } if (subgroup.ActionId != null) { subgroupEl.Background = GetActionBackgroundBrush(); } } if (group.ActionId != null) { g.Background = GetActionBackgroundBrush(); } return(g); } }