In ItemsControl
I have placed my Collection of Items. As this collection can be very huge, I try to implement some paging - When scroll to the end of visible scroll area, add new items to ItemsControl
.
Detecting of scroll bottom I've used from this answers How to find that ScrollViewer is scrolled to the end in WPF?
But I need to implement Adding
of items.
if (scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight &&
_productsViewModel.ProductTotal > pageCount*ConfigurationProvider.ItemsPerProductPage)
{
pageCount++;
_productsViewModel.RunPaginationWorker(pageCount);
}
Items are added in BG Worker. As parameter I send pageNumber
which is amount of times when user scroll to the end of scroll.
In BG CompleteWork event, I receive items and try to bind them to Property which is binded to ItemsControl
var items= (e.Result) as List<ItemDto>;
Items.AddRange(items);
OnPropertyChanged("Items");
But this doesn't work, it seems like Property Items
isn't changed.
public List<ItemDto> Items
{
get { return _items; }
set
{
_items= value;
OnPropertyChanged("Items");
}
}
And Xaml Binding
<ItemsControl VerticalAlignment="Top" MaxWidth="650" HorizontalAlignment="Center" Margin="10,40,10,0" Name="Items"
ItemsSource="{Binding Items}" AlternationCount="{Binding Path=Items.Count,FallbackValue='100'}">
...
</ItemsControl>