5

TreeView doesn't have ScrollIntoView() method
The only way is to call TreeVewItem.BringIntoView() for the corresponding data item container.
But if node is invisible and no container is generated yet, ItemsControl.ItemContainerGenerator.ContainerFromItem() will return null.

So there should be some way to force ItemContainerGenerator to create container for the item.

The reasonable question is: How can node be expanded and stay invisible?!

Easy! IsExpanded is bound to VM's property. And UI virtualization works as expected:
Event hanlder for TreeViewItem.Expanded was called ony when manual scrolling to the item was done.

Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137

1 Answers1

1

I can't guarantee this issue is similar enough to help, but I thought since I couldn't find a good answer for my own issue I would post here as this is similar and I figured out how to work around my issue.

I am working with a Canvas control and have complex UI elements that are placed on that canvas and have ItemsControl controls as a part of their XAML UI definitions. The ItemsControl's have defined DataTemplates set in their ItemTemplates.

Because of this, certain aspects of my objects will only fully generate once the Visual Tree has been updated. This isn't an issue with dragging and dropping and working with the items as the canvas is being worked on because the ItemContainerGenerator has already generated the items when I need them. But it is an issue when trying to regenerate the items from the database at Canvas load time before the visual tree has drawn itself.

I found the only real way to get around this problem was to only start working on placing "secondary objects" on the canvas (objects that tie into objects that the ItemContainerGenerators make) once the LayoutUpdated event for the canvas has been fired.

public class DesignerCanvas : Canvas
{
  public void LoadCanvasFromDB()
  {
    ...
    [loading items from the database, part one]
    LayoutUpdated += DesignerCanvas_LayoutUpdated;
  }

  void DesignerCanvas_LayoutUpdated(object sender, EventArgs e)
  {
    LayoutUpdated -= DesignerCanvas_LayoutUpdated;
    [loading items from the database which tie to UI elements from part one]
James Eby
  • 1,784
  • 20
  • 25