/// <summary> /// Returns the offset for the top item /// </summary> /// <param name="subgroups"></param> /// <returns></returns> private static double GetSubgroupsTopMarginOffset(IList <AdaptiveSubgroup> subgroups) { bool hasImage = false; double maxOffset = 0.0; // Look through each subgroup that has children foreach (var subgroup in subgroups.Where(i => i.Children.Any())) { var firstNode = subgroup.Children.Where(i => IsChildInline(i)).First(); double itemOffset = 0; if (firstNode is AdaptiveTextField) { bool ignore; TextStyleInfo textStyleInfo = AdaptiveGenerator_Text.GetStyleIndex((firstNode as AdaptiveTextField).HintStyle, out ignore); int lineStyleIndex = textStyleInfo.Index; itemOffset = AdaptiveGenerator_Text.DefaultTypeRamp[lineStyleIndex].TopOffset; } else if (firstNode is AdaptiveImage) { hasImage = true; } if (itemOffset > maxOffset) { maxOffset = itemOffset; } } if (hasImage && maxOffset < AdaptiveConstants.DefaultImageMargin) { maxOffset = AdaptiveConstants.DefaultImageMargin; } return(maxOffset); }
private static void GenerateItems( IEnumerable <AdaptiveChildElement> children, UIElementCollection container, bool isFirstGroup, bool isInsideGroup, double topMarginOffset, Thickness externalMargin) { int previousLineStyleIndex = -1; bool isFirst = true; bool needsImageMargin = false; foreach (var node in children.Where(i => IsChildInline(i))) { FrameworkElement uiChild = null; // If text if (node is AdaptiveTextField) { uiChild = AdaptiveGenerator_Text.GenerateText( textField: node as AdaptiveTextField, isFirst: isFirst, isFirstGroup: isFirstGroup, previousLineStyleIndex: previousLineStyleIndex, topMarginOffset: topMarginOffset, needsImageMargin: needsImageMargin, lineStyleIndex: out previousLineStyleIndex); needsImageMargin = false; } // If image else if (node is AdaptiveImage) { var imageNode = node as AdaptiveImage; // An image on top of first group have 0 margin // An image on top of another group should respond to topMarginOffset // An image not on top of a group should have DefaultImageMargin double topMargin = isFirst ? (isFirstGroup ? 0.0 : topMarginOffset) : AdaptiveConstants.DefaultImageMargin; uiChild = AdaptiveGenerator_Image.GenerateImage( imageNode: imageNode, topMargin: topMargin, isInsideGroup: isInsideGroup, needsMargin: out needsImageMargin); previousLineStyleIndex = -1; } // If group else if (node is AdaptiveGroup) { uiChild = GenerateGroup( group: node as AdaptiveGroup, isFirstGroup: isFirstGroup && isFirst, needsImageMargin: needsImageMargin, externalMargin: externalMargin); needsImageMargin = false; previousLineStyleIndex = -1; } // If progress bar else if (node is AdaptiveProgress) { uiChild = AdaptiveGenerator_Progress.Generate( progress: node as AdaptiveProgress); needsImageMargin = false; previousLineStyleIndex = -1; } if (uiChild != null) { isFirst = false; container.Add(uiChild); } } }