在Silverlight中使用Telerik RadDataPager(重新绑定数据后出现问题)

时间:2014-11-20 12:11:00

标签: xaml silverlight mvvm telerik

我正在使用MVVM框架。我的问题是我将PagedCollectionView绑定到radgridview并使用raddatapager我想做分页。因为我是新手,任何人都可以告诉我哪里出错了。此外,在获取记录时有一个问题,这适用于800条记录,但它不适用于1000以上的记录(附加了Web服务代码)。

在Web服务中,我使用此函数获取列表:

public List<GetStudents> GetStudentsListForUpdate(int schoolId, int academicYearId)
{
     return new DbHelper().Find(StudentAdmissionCommands.GetStudentsListForUpdate(schoolId, academicYearId), new GenericObjectBuilder<GetStudents>());
}

![第一次加载页面时附加快照] [1]
在ViewModel中,我像这样定义了Pagedcollection视图:

PagedCollectionView pcv;

public PagedCollectionView Pcv
{
   get { return pcv; }
   set { pcv = value; OnPropertyChanged("Pcv"); }
}

//This function written to get student's list
public void GetStud()
{
   Studlist.Clear();
   RootVisualHelper.SetBusy(true);
   StudentAdmissionServiceClient client = new StudentAdmissionServiceClient();
   client.GetStudentsListForUpdateCompleted += (Cs, Ea) =>
   {
      if (Ea.Error == null)
      {
         RootVisualHelper.SetBusy(false);
         if (Ea.Result.ToList().Count == 0)
         {
            EmptyMessageVisibility = "Visible";
         }
         else
         {
            EmptyMessageVisibility = "Collapsed";
            foreach (var item in Ea.Result)
            {
               Studlist.Add(item);
            }
            Pcv = new PagedCollectionView(Studlist);
            Pcv.GroupDescriptions.Clear();
            Pcv.GroupDescriptions.Add(new PropertyGroupDescription("AllocatedClass"));
         }
      }
   };
   client.GetStudentsListForUpdateAsync(SchoolIdLog, AcademicYearId);
}

在Xaml中,RadGridView绑定:

<telerik:RadGridView ItemsSource="{Binding Pcv}" SelectedItem="{Binding SelectedStudentList,Mode=TwoWay}"
                     telerik:StyleManager.Theme="{Binding Theme,Mode=TwoWay}"
                     helpers:CustomFilterBehavior.TextBox="{Binding ElementName=textBoxFilterValue}"
                     ShowColumnFooters="True" ShowGroupPanel="False"
                     AutoGenerateColumns="False" IsReadOnly="True" Grid.Row="3"
                     Grid.ColumnSpan="2" x:Name="RadGridView1"
                     CanUserFreezeColumns="False" GroupRenderMode="Flat"
                     RowIndicatorVisibility="Collapsed">
    <interactivity:Interaction.Triggers>
        <interactivity:EventTrigger EventName="RowActivated">
            <shared:EventToCommandTrigger Command="{Binding UpdateStudentCommand}" />
        </interactivity:EventTrigger>
    </interactivity:Interaction.Triggers>

    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding StudentRollNo}" Header="Student Code" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding StudentRegNo}" Header="Reg No." />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding StudentEsisNo}" Header="Esis No." />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding StudentName}" Header="Student Name" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding UserName}" Header="User Name" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding AllocatedClass}" Header="Class" />

        <telerik:GridViewDataColumn DataMemberBinding="{Binding Gender}" Header="Gender" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding DateOfBirth,StringFormat=dd/MM/yyyy}"
                                    Header="Date Of Birth" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ParentName}" Header="Parent Name" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ParentMobile}" Header="Father Mob. No." />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding MotherMobile1}" Header="Mother Mob. No." />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding StudentType}" Header="Student Type" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

<telerik:RadDataPager PageSize="100" Grid.Row="4"
                      FontSize="12" Margin="0,-1,0,0"
                      Source="{Binding Items, ElementName=RadGridView1}"
                      IsTotalItemCountFixed="false"
                      DisplayMode="FirstLastPreviousNextNumeric, Text" /> 

我是否必须处理pagedcollection视图的事件?如果是这样如何处理MVVM模式?

0 个答案:

没有答案