XAML-based UI technologies have a capability called UI Virtualization which reduces memory consumption and processing time when dealing with large collections of data presented in items-based UIs (ItemsControls).
In order to allow this, while keeping the capability to update the UI whenever items are added/removed/changed in the underlying data collection, you need to DataBind your UI to an ObservableCollection<T>
:
<ListBox ItemsSource="{Binding}"/>
code behind:
var numbers = Enumerable.Range(0,100);
DataContext = new ObservableCollection<int>(numbers);
Keep in mind that the declarative, DataBinding-based approach in XAML based UI technologies is really different from the procedural approach in other frameworks. In XAML, you never need to create UI elements in procedural code, you define them in XAML and then DataBind the UI to a relevant collection of Data Items, and the UI framework takes care of the rest.