How do I force the ItemContainerGenerator to create a container for the item, or How do I scroll the TreeView to an extended node when UI virtualization is enabled?

TreeView has no method. ScrollIntoView()


The only way is to call the TreeVewItem.BringIntoView()

data items on the appropriate container.
But if the node is invisible and the container hasn't been created yet, ItemsControl.ItemContainerGenerator.ContainerFromItem()

will return null

.

So, there must be some way to get the ItemContainerGenerator to create a container for the item.

Reasonable question: how can a node be expanded and remain invisible?

Easy! IsExpanded

bound to the VM property. And UI virtualization works as expected:
The hanlder event for TreeViewItem.Expanded was fired when manual scrolling to the item was done.

+3


source to share


1 answer


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

I am working with a Canvas element and have complex UI elements that are hosted on that canvas and have ItemsControls as part of their XAML UI definitions. The ItemsControl has defined DataTemplates in ItemTemplates .

Because of this, some aspects of my objects will only be fully generated after updating the Visual Tree. It's not a drag and drop issue when working with the canvas, because the ItemContainerGenerator has already created the items when I need them. But this is a problem when trying to regenerate items from the database at the time the Canvas is loaded before the visual tree has drawn itself.



I found the only real way to get around this problem was to start working on placing "secondary objects" on the canvas (objects that are bound to objects created by ItemContainerGenerators ) after the LayoutUpdated event for the canvas was 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]

      

+1


source







All Articles