I need to make a grid with paging.
For example, take this article: http://dotnetslackers.com/Silverlight/re-289981_How_To_Populate_RadGridView_for_Silverlight_distinct_filters_asynchronously_using_WCF_RIA_Services.aspx
Doing like this:
The first page is displayed correctly.
I can't move to another page, because the method CollectionChanged (and in the Refresh method, respectively) in the class PagingCollectionView PageIndex property is always 0.
I try to debug and see what PageChanging and PageChanged events called twice.
In the PageChanging event everything is fine, but in the PageChanged event in PagingCollectionView class PageIndex property initially has the correct value and then reset to 0.
So, in going through the pages, I still stay on the first page.
What am I doing wrong?
For example, take this article: http://dotnetslackers.com/Silverlight/re-289981_How_To_Populate_RadGridView_for_Silverlight_distinct_filters_asynchronously_using_WCF_RIA_Services.aspx
Doing like this:
<!-- XAML -->
<
telerik:RadGridView
HorizontalAlignment
=
"Stretch"
Name
=
"AllStudents"
VerticalAlignment
=
"Stretch"
IsBusy
=
"{Binding Path=Students.IsLoading, Mode=OneWay}"
Margin
=
"0,0,0,26"
ItemsSource
=
"{Binding Students}"
/>
<
telerik:RadDataPager
Source
=
"{Binding Students}"
VerticalAlignment
=
"Bottom"
/>
// C# (DataContext class)
public
class
MainDataContext
{
private
PagingCollectionView _students;
public
PagingCollectionView Students
{
get
{
if
(_students !=
null
)
return
_students;
var collection =
new
RadObservableCollection<Entity>();
_students =
new
PagingCollectionView(collection) { PageSize = 15 };
_students.MoveToFirstPage();
_students.PageChanging += view_PageChanging;
_students.PageChanged += view_PageChanged;
Refresh();
return
_students;
}
}
private
void
Refresh()
{
_students.SetIsLoading(
true
);
const
string
QUERY = @"
<fetch mapping=
'logical'
count=
'{0}'
page=
'{1}'
version=
'1.0'
>
<entity name=
'contact'
>
<all-attributes />
</entity>
</fetch>";
var query =
string
.Format(QUERY, _students.PageSize, _students.PageIndex + 1);
SilverCrmSoap.Helpers.SoapHelper.BeginExecuteFetch(query,
delegate
(IAsyncResult result)
{
var response = ((IOrganizationService)result.AsyncState).EndExecute(result);
var entities = ((EntityCollection)response[
"EntityCollection"
]);
Deployment.Current.Dispatcher.BeginInvoke((ThreadStart)
delegate
{
var collection = (RadObservableCollection<Entity>)_students.SourceCollection;
collection.SuspendNotifications();
collection.Clear();
collection.AddRange(entities.Entities);
collection.ResumeNotifications();
_students.SetIsLoading(
false
);
_students.Refresh();
_students.SetTotalItemsCount(30000);
_students.CollectionChanged += CollectionChanged;
});
});
}
void
view_PageChanging(
object
sender, System.ComponentModel.PageChangingEventArgs e)
{
}
void
view_PageChanged(
object
sender, EventArgs e)
{
}
void
CollectionChanged(
object
sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
_students.CollectionChanged -= CollectionChanged;
Refresh();
}
}
public
class
PagingCollectionView : QueryableCollectionView
{
public
PagingCollectionView(IEnumerable source) :
base
(source) {}
protected
override
IQueryable CreateView()
{
return
IsGrouped ? QueryableSourceCollection.GroupBy(GroupDescriptors) : QueryableSourceCollection;
}
internal
void
SetTotalItemsCount(
int
count)
{
TotalItemCount = count;
}
internal
void
SetIsLoading(
bool
value)
{
IsLoading = value;
}
}
I can't move to another page, because the method CollectionChanged (and in the Refresh method, respectively) in the class PagingCollectionView PageIndex property is always 0.
I try to debug and see what PageChanging and PageChanged events called twice.
In the PageChanging event everything is fine, but in the PageChanged event in PagingCollectionView class PageIndex property initially has the correct value and then reset to 0.
So, in going through the pages, I still stay on the first page.
What am I doing wrong?