【发布时间】:2011-03-22 14:20:06
【问题描述】:
我们有一个包含各种元素和数据网格的表单。当列表框包含在滚动查看器中时,当我们增加窗口大小时,一切都很好。当窗口大小减小时,列表框的高度保持不变,垂直滚动条变为活动状态。如果您摆脱列表框上的高度绑定,列表框将达到其最大所需高度。如果我们根本没有列表框,那么边框的行为就像我们想要的那样。
我们可以使用下面的代码来模拟我们的问题。
<Window
x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="150"
Width="525">
<Grid
Margin="10">
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Border
x:Name="border"
MinHeight="40" />
<ListBox
Height="{Binding ElementName=border, Path=ActualHeight}">
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
</ListBox>
<ToolBar
Grid.Row="1">
<Button
Content="Add" />
</ToolBar>
</Grid>
</ScrollViewer>
</Grid>
</Window>
我们如何让 ListBox 像没有 ListBox 时一样调整边框的大小?
【问题讨论】:
标签: wpf listbox scrollviewer