Hey Telerik!
to achieve a virtualization on a gridview (infinite scrolling) without the MVVM I followed this doc:
works like a charm.
but my attempt to have it working using a viewmodel doesn't. The list comes empty
What is the best way to have a virtualization on a gridview, while maintaining MVVM pattern?
Thank you for your help!
here is my code:
MainWindow.xaml
<
Window
x:Class
=
"TelerikVirtualization.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"MainWindow"
Height
=
"900"
Width
=
"700"
xmlns:my
=
"clr-namespace:TelerikVirtualization"
>
<
Window.Resources
>
<
my:ViewModel
x:Key
=
"ViewModel"
/>
</
Window.Resources
>
<
Grid
DataContext
=
"{StaticResource ViewModel}"
>
<
telerik:RadGridView
ItemsSource
=
"{Binding View}"
>
</
telerik:RadGridView
>
</
Grid
>
</
Window
>
MainWindow.xaml.cs
using
System.Windows;
namespace
TelerikVirtualization
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
}
}
}
ViewModel.cs (if it is possible, I would like to move the GetList() to a Load() method. so that I can handle the Window_Loaded event to Load() it, thus not having to load it every time this class gets initialized. but for now it is fine like this)
using
PropertyChanged;
using
System;
using
System.Collections.Generic;
using
System.Collections.ObjectModel;
using
Telerik.Windows.Data;
namespace
TelerikVirtualization
{
[ImplementPropertyChanged] //install Fody.PropertyChanged nugget for this
public
class
ViewModel
{
public
VirtualQueryableCollectionView View;
Controller controller;
public
ViewModel()
{
controller =
new
Controller();
View =
new
VirtualQueryableCollectionView(controller.GetList()) { LoadSize = 10 };
}
}
}
Controller.cs
using
System.Linq;
namespace
TelerikVirtualization
{
public
class
Controller
{
public
IQueryable GetList()
{
return
new
DataClasses1DataContext().MyTables;
}
}
}