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; } }}