我要疯了,试图弄清楚这一点。我有一个 DockPanel,其中一些东西停靠在 Top 上,还有一个 ItemsControl 作为它的中心内容(它表现为一个包含更多 DockPanel 的 WrapPanel)。
我希望中心 ItemsControl 根据需要扩展父 DockPanel 的宽度。我不希望停靠在 DockPanel 顶部的东西导致 DockPanel 展开,但我希望它使用 ItemsControl 的宽度所请求的任何空间。
下面是一些非常简化的 XAML,仍然可以捕获行为:
<Window x:Class="SizingTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="Width" Height="150">
<Grid>
<DockPanel>
<TextBlock DockPanel.Dock="Top">Here's some really long text that should not force the window to expand. Just clip if it's wider than the buttons.</TextBlock>
<WrapPanel Orientation="Vertical">
<Button>Button 1</Button>
<Button>Button 2</Button>
<Button>Button 3</Button>
<Button>Button 4</Button>
<Button>Button 5</Button>
<Button>Button 6</Button>
<Button>Button 7</Button>
<Button>Button 8</Button>
<Button>Button 9</Button>
<Button>Button 10</Button>
</WrapPanel>
</DockPanel>
</Grid>
</Window>
换句话说,WrapPanel/DockPanel/Grid/Window 应该调整它们的宽度以适应 WrapPanel 的按钮列,但我希望在用完 WrapPanel 请求的所有可用空间后简单地裁剪 TextBlock。调整窗口高度(这会导致 WrapPanel 调整自身并添加/删除列)应该会导致 TextBlock 更改宽度 - 和剪辑 - 以匹配 WrapPanel。我该如何做?