IsVirtualizing=“true”的 WPF TreeView改变焦点和滚动时跳转
我做了一个简单的例子来重现我在使用 TreeView
时遇到的问题。如果我在 TreeView
中选择一个项目,向下滚动,更改焦点
,然后再次在 TreeView
中选择一个项目,列表就会开始跳来跳去。
仅当我有 VirtualizingStackPanel.IsVirtualizing="True" 时才会发生这种情况。这是一个已知问题吗?有解决办法吗?
因此,要重现:
- 选择列表中的项目 1。
- 向下滚动到列表底部
- 单击顶部的文本框。
- 选择列表中的项目 30
我正在使用 .Net 3.5 SP1,并且我已经在 64 位 XP 和 Vista 上尝试过它。我没有在其他环境下尝试过。
更新:我已经在.Net 4.0 Beta 中进行了测试,并且没有出现该问题。某处有修补程序吗?
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Grid.Row="0"></TextBox>
<TreeView Grid.Row="1"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Standard"
>
<TreeView.Items>
<TreeViewItem Header="Header 1" IsExpanded="True">
<TreeViewItem.Items>
<TreeViewItem Header="Item 1" />
<TreeViewItem Header="Item 2" />
<TreeViewItem Header="Item 3" />
<TreeViewItem Header="Item 4" />
<TreeViewItem Header="Item 5" />
<TreeViewItem Header="Item 6" />
<TreeViewItem Header="Item 7" />
<TreeViewItem Header="Item 8" />
<TreeViewItem Header="Item 9" />
<TreeViewItem Header="Item 10" />
<TreeViewItem Header="Item 11" />
<TreeViewItem Header="Item 12" />
<TreeViewItem Header="Item 13" />
<TreeViewItem Header="Item 14" />
<TreeViewItem Header="Item 15" />
<TreeViewItem Header="Item 16" />
<TreeViewItem Header="Item 17" />
<TreeViewItem Header="Item 18" />
<TreeViewItem Header="Item 19" />
<TreeViewItem Header="Item 20" />
<TreeViewItem Header="Item 21" />
<TreeViewItem Header="Item 22" />
<TreeViewItem Header="Item 23" />
<TreeViewItem Header="Item 24" />
<TreeViewItem Header="Item 25" />
<TreeViewItem Header="Item 26" />
<TreeViewItem Header="Item 27" />
<TreeViewItem Header="Item 28" />
<TreeViewItem Header="Item 29" />
<TreeViewItem Header="Item 30" />
</TreeViewItem.Items>
</TreeViewItem>
</TreeView.Items>
</TreeView>
</Grid>
</Window>
任何帮助将不胜感激!
I've made a simple example to reproduce a problem I'm having with the TreeView
. If I select an item in the TreeView
, scroll down, change the Focus
, and then select an item in the TreeView
again, the list starts jumping around.
This only happens if I have VirtualizingStackPanel.IsVirtualizing="True"
. Is this a known problem? Is there a work around?
So to reproduce:
- Select Item 1 in the list.
- Scroll down to the bottom of the list
- Click the TextBox up top.
- Select Item 30 in the list
I'm using .Net 3.5 SP1 and I've tried it for 64bit XP and Vista. I haven't tried it on other environments.
Update: I've tested in .Net 4.0 Beta and the issue doesn't occur. Is there a hotfix somewhere?
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Grid.Row="0"></TextBox>
<TreeView Grid.Row="1"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Standard"
>
<TreeView.Items>
<TreeViewItem Header="Header 1" IsExpanded="True">
<TreeViewItem.Items>
<TreeViewItem Header="Item 1" />
<TreeViewItem Header="Item 2" />
<TreeViewItem Header="Item 3" />
<TreeViewItem Header="Item 4" />
<TreeViewItem Header="Item 5" />
<TreeViewItem Header="Item 6" />
<TreeViewItem Header="Item 7" />
<TreeViewItem Header="Item 8" />
<TreeViewItem Header="Item 9" />
<TreeViewItem Header="Item 10" />
<TreeViewItem Header="Item 11" />
<TreeViewItem Header="Item 12" />
<TreeViewItem Header="Item 13" />
<TreeViewItem Header="Item 14" />
<TreeViewItem Header="Item 15" />
<TreeViewItem Header="Item 16" />
<TreeViewItem Header="Item 17" />
<TreeViewItem Header="Item 18" />
<TreeViewItem Header="Item 19" />
<TreeViewItem Header="Item 20" />
<TreeViewItem Header="Item 21" />
<TreeViewItem Header="Item 22" />
<TreeViewItem Header="Item 23" />
<TreeViewItem Header="Item 24" />
<TreeViewItem Header="Item 25" />
<TreeViewItem Header="Item 26" />
<TreeViewItem Header="Item 27" />
<TreeViewItem Header="Item 28" />
<TreeViewItem Header="Item 29" />
<TreeViewItem Header="Item 30" />
</TreeViewItem.Items>
</TreeViewItem>
</TreeView.Items>
</TreeView>
</Grid>
</Window>
Any help would be much appreciated!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,它看起来像一个错误,并且有一个 大量修补程序。您是否启用了 Windows 更新?
Well, it looks like a bug and there is a plenty of hotfixes. Do you have Windows Update enabled?