0

I am interested in using the ExpanderView control with the following behavior:

  • I know if there should be expandable items when populating the header, but I do not know how many and do not want to add the items until the header is tapped to expand it (e..g because the items need to be retrieved using a web request).
  • I will eventually have ExpanderControls as items in a list, but I am playing with the simplest scenario first.

Seems like this would be a common scenrario, to lazy load the expandable items.

So I have implemented simple code in the Expanded event to load items if they are not already loaded:

if (!expanded)
{
    for (var x = 1; x <= 10; x++)
    {
        ((ExpanderView)sender).Items.Add(new TextBlock() { Text = "Added this on expanded " + x.ToString() });
    }

    expanded = true;
}

The problem with this is that the items are not rendered properly the first time (anything below the control is not "pushed down" to allow the space for the items), presumably because the control does not know the item content in advance. On subsequent expansion, the items are displayed properly.

Anyone know how I can achieve this lazy loading with the ExpanderView?

Dean McCrae
  • 149
  • 1
  • 4

1 Answers1

3

Try doing a UpdateLayout() on your expanderview after the items have been added. If you are doing the expansion in the Expanded listener you can just do the following.

private void expander_Expanded(object sender, System.Windows.RoutedEventArgs e)
{
     // add item here
     ((ExpanderView) sender).UpdateLayout()
}
idunnololz
  • 8,058
  • 5
  • 30
  • 46