1.定义好分页控件的数据源即可,任何设置RadGridView的数据源指向分页控件即可
RadGridView设置:
ItemsSource="{Binding PagedSource, ElementName=radDataPager}"
2.设置分页控件是Source
this.radDataPager.Source = employees;
或者 Source="{Binding DataSouce,Mode=TwoWay}"
有左边导航的,也只要把过滤好的数据源直接扔给分页控件就好了,其他的就有分页控件进行处理了。
我比较喜欢ItemsSource="{Binding PagedSource, ElementName=radDataPager}"
这句话,感觉好神奇
<UserControl x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot"
Background="White">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<telerik:RadGridView x:Name="radGridView"
ItemsSource="{Binding PagedSource, ElementName=radDataPager}"
AutoGenerateColumns="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding CompanyName}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Title}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<telerik:RadDataPager x:Name="radDataPager"
Grid.Row="1"
DisplayMode="All"
PageSize="5"
Margin="0,10,0,0" />
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace SilverlightApplication2
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
ObservableCollection<Employee> employees = new ObservableCollection<Employee>();
employees.Add(new Employee("Maria Anders", "Alfreds Futterkiste", "Sales Representative"));
employees.Add(new Employee("Ana Trujillo", "Ana Trujillo Emparedados y helados", "Owner"));
employees.Add(new Employee("Antonio Moreno", "Antonio Moreno Taqueria", "Owner"));
employees.Add(new Employee("Thomas Hardy", "Around the Horn", "Sales Representative"));
employees.Add(new Employee("Hanna Moos", "Blauer See Delikatessen", "Sales Representative"));
employees.Add(new Employee("Frederique Citeaux", "Blondesddsl pere et fils", "Marketing Manager"));
employees.Add(new Employee("Martin Sommer", "Bolido Comidas preparadas", "Owner"));
employees.Add(new Employee("Laurence Lebihan", "Bon app'", "Owner"));
employees.Add(new Employee("Elizabeth Lincoln", "Bottom-Dollar Markets", "Accounting manager"));
employees.Add(new Employee("Victoria Ashworth", "B's Beverages", "Sales representative"));
employees.Add(new Employee("Thomas Hardy", "Around the Horn", "Sales Representative"));
employees.Add(new Employee("Hanna Moos", "Blauer See Delikatessen", "Sales Representative"));
employees.Add(new Employee("Frederique Citeaux", "Blondesddsl pere et fils", "Marketing Manager"));
employees.Add(new Employee("Martin Sommer", "Bolido Comidas preparadas", "Owner"));
employees.Add(new Employee("Laurence Lebihan", "Bon app'", "Owner"));
employees.Add(new Employee("Elizabeth Lincoln", "Bottom-Dollar Markets", "Accounting manager"));
employees.Add(new Employee("Victoria Ashworth", "B's Beverages", "Sales representative"));
this.radDataPager.Source = employees;
}
}
public class Employee
{
public Employee(string name, string companyName, string title)
{
this.Name = name;
this.CompanyName = companyName;
this.Title = title;
}
public string Name
{
get;
set;
}
public string CompanyName
{
get;
set;
}
public string Title
{
get;
set;
}
}
}