WPF 错误? Grid 的列不容纳 ListBox 滚动条
UserControl
的高度减小时,最左侧列的宽度不会增加以容纳出现的 ListBox
滚动条:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Example">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2">Example text</TextBlock>
<ListBox Grid.Row="1" Grid.Column="0">
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
<ListBoxItem>Four</ListBoxItem>
<ListBoxItem>Five</ListBoxItem>
</ListBox>
<Expander Grid.Row="1" Grid.Column="1" Header="Expander" />
</Grid>
</UserControl>
在以下示例中,当 带有 ColumnSpan
属性的 被删除,列大小按预期调整。这是 WPF 中的错误吗?
In the following example, the leftmost column's width does not increase to accommodate the ListBox
's scrollbar that appears when the UserControl
's height is decreased:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Example">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2">Example text</TextBlock>
<ListBox Grid.Row="1" Grid.Column="0">
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
<ListBoxItem>Four</ListBoxItem>
<ListBoxItem>Five</ListBoxItem>
</ListBox>
<Expander Grid.Row="1" Grid.Column="1" Header="Expander" />
</Grid>
</UserControl>
When the TextBlock
with the ColumnSpan
attribute is removed the column resizes as expected. Is this a bug in WPF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来这是ListBox 滚动条和 WPF 网格的已知错误< /a>.微软还指出,他们可能不会在 4.0 中修复这个问题。
It appears this is a known bug with the ListBox scrollbar and the WPF Grid. Microsoft also notes they will probably not have this fixed in 4.0.