Data Virtualization on ListView

Topics: Bugs, Conventions
Apr 22, 2013 at 8:44 PM
Hi!

I'm trying to implement Data Virtualization on my App. Something like on this post:
LINK
I was able to do it, not using Caliburn, but I'm not accomplishing it using caliburn.
Is it possible?

Code following:

ViewModel.cs
public class MainViewModel : ViewModelBase
    {
        // constructor
        public MainViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            List1 = new VirtualItemList();
            List1.TotalSize = 10000;
        }

        protected override void OnInitialize()
        {
            base.OnInitialize();
        }

        private VirtualItemList list1;

        public VirtualItemList List1
        {
            get { return list1; }
            set { list1 = value; this.NotifyOfPropertyChange(() => List1); }
        }
    }
View:
...
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel x:Name="stackItems" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" >
            <ListView x:Name="List1" IsSwipeEnabled="True" Width="500" SelectionMode="None">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="10">
                            <TextBlock Text='{Binding Title}' Foreground="White" />
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
    </StackPanel>
</Grid>
VirtualItemList.cs
public class VirtualItemList : ObservableCollection<Item>, ISupportIncrementalLoading
    {
        private DataService service;

        public DataService Service
        {
            get { return service; }
            set { service = value; }
        }

        public VirtualItemList()
        {
            this.Service = new DataService();
        }
        private int totalSize;

        public int TotalSize
        {
            get { return totalSize; }
            set { totalSize = value; }
        }

        public bool HasMoreItems
        {
            get
            {
                return (this.Count < this.TotalSize);
            }
        }

        public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            var start = this.Count;

            CoreDispatcher dispatcher = Window.Current.Dispatcher;

            return Task.Run<LoadMoreItemsResult>(
                async () =>
                {
                    var result = await this.Service.getItems(start, (int)count);

                    await dispatcher.RunAsync
                    (
                        CoreDispatcherPriority.Normal,
                        () =>
                        {
                            foreach (var item in result)
                                this.Add(item);
                        }
                    );

                    return new LoadMoreItemsResult() { Count = (uint)result.Count() };
                }).AsAsyncOperation<LoadMoreItemsResult>();
        }
    }
Apr 22, 2013 at 8:53 PM
Sorry. I just got it working. There was a problem on the view.