How to reset the height of ScrollView? When child elements changes

I am creating a “backpack” UI and I need to change the number of child elements of the ScrollView.

But it is a bit strange that the ScrollView does not automatically refresh to the right height.

As you can see from the image below, I only have three items, but the ScrollView has a long height.
I wonder if there is something wrong with my code writing?
Please help me, thank you very much.

void Refresh() {
  ScrollView d_scroller = root.Query<ScrollView>();
  // Clear existing elements
  d_scroller.Clear();
  // Adding new elements according to the list
  for (int i = 0; i < lists.Count; i++) {
    VisualElement em = new VisualElement();
    d_scroller.Add(em);
  }
}

Hey there, ended up here, still have the same issue, did you find a solution by any chance? @littenli

You need to call either RefreshItems() or Rebuild()

Which one you need will depend on your use case. Rebuild is slower, so I suggest starting with RefreshItems first.

Thanks!