Hi all,
I use VirtualQueryableCollectionView.ItemsLoading together with asynchronous service. I use RadGridView and RadDataPager.
Everything looks fine until user click pager faster than my service response. If service is slow then VirtualQueryableCollectionView.Load is called later than user clicks on pager again.
When my service call finishes (for old page 1 -> Load is made for items on page 1) no ItemsLoading is fired for page 2. Even user see already page 2 on the screen no one asked for page 2.
I tried to use Q1 2011 SP1, but does not work as well.
Bellow is a source which simulates slow service by right click. Run the code (RadGridView and RadDataPager are bind to Groups). If you right click (simulation of service response) before changing the page then OK. But if you first change the page and just then right click (service response for old page) then no one asks for just shown page.
What is a right usage in this case?
Best regards,
Dalibor
Code looks like this:
namespace
VirtualPage
{
public
partial
class
MainPage : UserControl, INotifyPropertyChanged
{
private
VirtualQueryableCollectionView groups;
public
VirtualQueryableCollectionView Groups
{
get
{
if
(groups ==
null
)
{
groups =
new
VirtualQueryableCollectionView();
groups.ItemsLoading += HandleItemsLoading;
groups.LoadSize = 20;
// by assigning a value to VirtualItemCount property, we can force the ItemsLoading
// event to fire
groups.VirtualItemCount = 10000;
}
return
groups;
}
private
set
{
if
(groups != value)
{
groups.ItemsLoading -= HandleItemsLoading;
groups = value;
if
( PropertyChanged !=
null
)
{
PropertyChanged(
this
,
new
PropertyChangedEventArgs(
"Groups"
));
}
}
}
}
public
MainPage()
{
InitializeComponent();
}
private
int
startIndex;
private
string
[] ar;
// simulation of slow service by right click
protected
override
void
OnMouseRightButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
base
.OnMouseRightButtonDown(e);
// simulation of delayed service callback
Debug.WriteLine(
string
.Format(
"---- Writting {0} count {1}"
, startIndex, ar.Length));
groups.Load(startIndex, ar);
/*
if((startIndex / groups.PageSize) != groups.PageIndex)
{
groups.NeedsRefresh = true;
}
*/
}
private
void
HandleItemsLoading(
object
sender, VirtualQueryableCollectionViewItemsLoadingEventArgs e)
{
Debug.WriteLine(
string
.Format(
"Asking from {0} count {1}"
, e.StartIndex, e.ItemCount));
// groups.Load(e.StartIndex, ar);
// do not load it now, load it later after async call (right click in this demo).
ar =
new
string
[e.ItemCount];
for
(
int
i = 0; i < e.ItemCount; i++)
{
ar[i] =
"s"
+ i;
}
startIndex = e.StartIndex;
}
public
event
PropertyChangedEventHandler PropertyChanged;
}
}