我试图在 Column/RowDefinition for Grids 中实现类似于 SharedSizeGroup 的东西。
简化案例:
<l:MyCustomPanel>
<l:MyCustomPanel>
<TextBlock l:MyCustomPanel.SharedWidth="t1" />
</l:MyCustomPanel>
<l:MyCustomPanel>
<TextBlock l:MyCustomPanel.SharedWidth="t1" />
</l:MyCustomPanel>
</l:MyCustomPanel>
根面板正在定义范围。具有相同 SharedWidth 的所有元素应具有相同的宽度。我已经实现了我的自定义测量和排列行为,但我努力让它与 SharedSize 模型一起工作。我怀疑我必须以某种方式通过两次排列过程?第一个找出默认尺寸(并收集最大宽度),然后再通过一次以将此最大宽度用作排列结果中的参数。但是我该怎么做呢?我想我不能在每个 ArrangeOverride 中运行两次传递,因为这会导致每个元素对其整个降序元素树进行两次传递?嗯。有什么建议么?
更新
这段代码更详细地说明了这个问题:
public class CustomPanel : Panel
{
protected override Size MeasureOverride(Size availableSize)
{
Children[0].Measure(availableSize);
return Children[0].DesiredSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
Children[0].Arrange(new Rect(new Point(), new Size(finalSize.Width / 2, finalSize.Height)));
return finalSize;
}
}
<StackPanel>
<l:CustomPanel>
<TextBox />
</l:CustomPanel>
</StackPanel>
在文本框中输入文本使其溢出时,它会扩展到不可用的空间...