本文整理汇总了C#中Windows.UI.Xaml.Controls.ContentControl.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# ContentControl.Measure方法的具体用法?C# ContentControl.Measure怎么用?C# ContentControl.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Controls.ContentControl
的用法示例。
在下文中一共展示了ContentControl.Measure方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureOverride
protected override Size MeasureOverride(Size availableSize)
{
// Clean previous arranges, no matter what
arranges.Clear();
// Remove previous added attribute group children
var nonAttributeChild = Children.OfType<FrameworkElement>().FirstOrDefault(fe => !(fe.DataContext is PersistentObjectAttribute));
while (nonAttributeChild != null)
{
Children.Remove(nonAttributeChild);
nonAttributeChild = Children.OfType<FrameworkElement>().FirstOrDefault(fe => !(fe.DataContext is PersistentObjectAttribute));
}
// Determine visible attributes, make sure others are hidden
var attributes = Children.OfType<FrameworkElement>().Select(c => Tuple.Create(c, (PersistentObjectAttribute)c.DataContext)).Where(attr =>
{
attr.Item1.Measure(availableSize);
return attr.Item1.DesiredSize.Height > 0 && attr.Item1.DesiredSize.Width > 0;
}).ToArray();
if (attributes.Length == 0)
return new Size(0d, 0d);
// Create groups and optional group controls (if more than one group)
var groupHeight = 0d;
var attributesByGroup = attributes.GroupBy(attr => attr.Item2.Group).ToArray();
var groups = attributesByGroup.Select(g =>
{
ContentControl groupControl = null;
if (attributesByGroup.Length > 1)
{
groupControl = new ContentControl { Content = g.Key, ContentTemplate = GroupTemplate };
Children.Add(groupControl);
groupControl.Measure(availableSize);
if (groupControl.DesiredSize.Height + VerticalSpacing > groupHeight)
groupHeight = groupControl.DesiredSize.Height;
}
return Tuple.Create(groupControl, g.ToArray());
}).ToArray();
// Calculate sizes and positions
var minHeight = attributes.Where(attr => attr.Item1.DesiredSize.Height > 0).Min(attr => attr.Item1.DesiredSize.Height) + VerticalSpacing;
var maxTop = 0d;
var maxWidth = 0d;
var top = 0d;
var left = 0d;
groups.Run(g =>
{
var childrenInThisColumn = new List<Tuple<FrameworkElement, Rect>>();
var colWidth = 0d;
if (g.Item1 != null)
{
childrenInThisColumn.Add(Tuple.Create(g.Item1 as FrameworkElement, new Rect(left, top, g.Item1.DesiredSize.Width, g.Item1.DesiredSize.Height)));
colWidth = g.Item1.DesiredSize.Width;
top += groupHeight;
}
g.Item2.Run(attr =>
{
var height = attr.Item1.DesiredSize.Height <= minHeight ? minHeight : Math.Ceiling(attr.Item1.DesiredSize.Height / minHeight) * minHeight;
height -= VerticalSpacing;
if (top + height > availableSize.Height && double.IsInfinity(availableSize.Width))
{
top = groupHeight;
left += Math.Min(availableSize.Width, Math.Max(MinAttributeWidth, colWidth)) + HorizontalSpacing;
maxWidth += Math.Min(availableSize.Width, Math.Max(MinAttributeWidth, colWidth)) + HorizontalSpacing;
childrenInThisColumn.Run(c => arranges.Add(Tuple.Create(c.Item1, new Rect(c.Item2.X, c.Item2.Y, Math.Min(availableSize.Width, Math.Max(MinAttributeWidth, colWidth)), c.Item2.Height))));
childrenInThisColumn.Clear();
colWidth = 0d;
top = groupHeight;
}
else if (top + height > maxTop)
maxTop = top + height;
var width = Math.Min(MinAttributeWidth, availableSize.Width);
childrenInThisColumn.Add(Tuple.Create(attr.Item1, new Rect(left, top, width, attr.Item1.DesiredSize.Height)));
top += height + VerticalSpacing;
if (width > colWidth)
colWidth = width;
});
childrenInThisColumn.Run(c => arranges.Add(Tuple.Create(c.Item1, new Rect(c.Item2.X, c.Item2.Y, Math.Min(availableSize.Width, Math.Max(MinAttributeWidth, colWidth)), c.Item2.Height))));
childrenInThisColumn.Clear();
if (double.IsInfinity(availableSize.Width))
{
left += Math.Min(availableSize.Width, Math.Max(MinAttributeWidth, colWidth)) + HorizontalSpacing;
top = 0d;
}
maxWidth += Math.Min(availableSize.Width, Math.Max(MinAttributeWidth, colWidth));
//.........这里部分代码省略.........