I have a Pivot Page with four pivots. In two of the pivots I have a ListBox which I fill with information in the form of a grid. I Bind the ListItems to an ObservableCollection which is filled with information fetched asynchronous from a WCF.
However, the UI seems to freeze when the DataContext is set and the UI is filling the ListBox with data. The more ListItems, the longer it freezes.
Edit: Calrification. I can still scroll the page up/down, but I can't swipe to navigate to a different pivot. The transition happens after the UI unfreezes.
Is there any way to fill the ListBox without freezing the UI?
Edit: Some sample code loosely explaining what happens.
The listbox
<ListBox Name="lbInterruptYesterday" ScrollViewer.VerticalScrollBarVisibility="Disabled"
ItemsSource="{Binding Interrupts}"
ItemTemplate="{StaticResource InterruptListItem}" Tap="Interrupt_OnTap">
</ListBox>
Interrupts is an ObservableCollection containing Interrupt objects.
InterruptListItem contains a grid with TextBlocks, the text is Binding to variables in an Interrupt-object.
I fetch the data with an asynchronous call to a WCF. When completed I do:
(sender, e) => Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//Some code handling the result which I put in the ObservableCollection
Production.Interrupts.add(new Interrupt());
//Set the DataContext
DataContext = Production;
});
And when the DataContext is set, the UI freezes until it is updated.