13

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:

  1. Select Item 1 in the list.
  2. Scroll down to the bottom of the list
  3. Click the TextBox up top.
  4. 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!!!

3
  • 2
    This is a nifty bug! It looks like this has been around for a while and Marco Zhou has looked into it on the MSDN forums. His proposed work around does not fix the issue however: bit.ly/4nJUme
    – rmoore
    Dec 18, 2009 at 23:28
  • Looks like the fix does indeed work, I had a build error, and so it wasn't using the new classes when I tested it.
    – rmoore
    Dec 18, 2009 at 23:35
  • I had the same problem in Silverlight Treeview
    – nipiv
    Aug 21, 2012 at 21:53

1 Answer 1

1

Well, it looks like a bug and there is a plenty of hotfixes. Do you have Windows Update enabled?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.