稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager

时间:2021-10-17 12:14:29
[索引页]
[源码下载]


稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager


作者: webabcd


介绍
Silverlight 3.0 控件一览:
  • AutoCompleteBox - 自动完成控件。当用户输入部分信息后,此控件可以基于指定的过滤算法在一个下拉框中陈列出匹配项
  • DataPager - 分页控件 


在线DEMO
http://www.cnblogs.com/webabcd/archive/2009/08/04/1538238.html


示例
1、演示 AutoCompleteBox(一次绑定全部数据或按需加载相关数据)
AutoCompleteBox.xaml
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager< navigation:Page  xmlns:input ="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"   x:Class ="Silverlight30.Control.AutoCompleteBox"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           mc:Ignorable
="d"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:navigation
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           d:DesignWidth
="640"  d:DesignHeight ="480"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           Title
="AutoCompleteBox Page" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
< Grid  x:Name ="LayoutRoot" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
< Grid.Resources >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
<!-- 用于在 AutoCompleteBox 中显示数据的模板 -->
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
< DataTemplate  x:Key ="dataTemplate" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
< StackPanel  Orientation ="Horizontal" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
< TextBlock  Text ="名字: "   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
< TextBlock  Text =" {Binding Name} "   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
< TextBlock  Text ="薪水: "   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
< TextBlock  Text =" {Binding Salary} "   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
</ StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
</ DataTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
</ Grid.Resources >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
< StackPanel  Orientation ="Horizontal"  VerticalAlignment ="Top" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
<!--
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                MinimumPrefixLength - 如需显示自动完成的匹配项,所需输入的最少字符数
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                IsTextCompletionEnabled - 是否在 Text 中显示当前匹配项的全部内容
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                MaxDropDownHeight - 下拉框的最大长度
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                FilterMode - 根据用户的输入,对数据源做过滤的方式,默认值:StartsWith [System.Windows.Controls.AutoCompleteFilterMode 枚举]
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    本例演示如何实现自定义的过滤
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                DropDownOpening, DropDownOpened, DropDownClosing, DropDownClosed - 顾名思义的几个事件
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
-->
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
< input:AutoCompleteBox  x:Name ="autoCompleteBox"  Width ="100"  Height ="30"  Margin ="10"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                                   MinimumPrefixLength
="0"  IsTextCompletionEnabled ="True"  MaxDropDownHeight ="100"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                                   FilterMode
="Custom" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
<!--
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    呈现数据的方式如下,也可以设置 AutoCompleteBox 的 ValueMemberBinding 属性
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
-->
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
< input:AutoCompleteBox.ItemTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
< DataTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                        
< StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            
< TextBlock  Text =" {Binding} "   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                        
</ StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
</ DataTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
</ input:AutoCompleteBox.ItemTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
</ input:AutoCompleteBox >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
<!--
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                ValueMemberPath - 在此属性指定的成员中做过滤,过滤参数为用户的输入
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                ItemTemplate - 指定用于显示数据的模板
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
-->
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
< input:AutoCompleteBox  x:Name ="autoCompleteBoxTemplate"  Width ="100"  Height ="30"  Margin ="10"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                                   ValueMemberPath
="Salary"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                                   ItemTemplate
=" {StaticResource dataTemplate} "   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
<!--
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                Populating, Populated - 调用 按需加载数据服务 的一对事件
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                MinimumPopulateDelay - 调用 按需加载数据服务 的延迟时间。即在用户的输入发生改变时,此时间后调用指定的服务
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
-->
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
< input:AutoCompleteBox  x:Name ="autoCompleteBoxPopulate"  Width ="100"  Height ="30"  Margin ="10"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                                   Populating
="autoCompleteBoxPopulate_Populating"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                                   MinimumPopulateDelay
="500" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
< input:AutoCompleteBox.ItemTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
< DataTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                        
< StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            
< TextBlock  Text =" {Binding} "   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                        
</ StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
</ DataTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
</ input:AutoCompleteBox.ItemTemplate >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
</ input:AutoCompleteBox >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
</ StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
</ Grid >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
</ navigation:Page >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager

EmployeeModel.cs
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPagerusing  System;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Net;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Controls;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Documents;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Ink;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Input;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Media;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Media.Animation;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Shapes;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
namespace  Silverlight30.Model
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
public class EmployeeModel
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
public string Name getset; }
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
public double Salary getset; }
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
public DateTime DateOfBirty getset; }
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager}

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager

AutoCompleteBox.xaml.cs
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPagerusing  System;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Collections.Generic;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Linq;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Net;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Controls;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Documents;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Input;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Media;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Media.Animation;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Shapes;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Navigation;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  Silverlight30.Model;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Xml.Linq;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
namespace  Silverlight30.Control
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
public partial class AutoCompleteBox : Page
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
public AutoCompleteBox()
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            InitializeComponent();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
this.Loaded += new RoutedEventHandler(AutoCompleteBox_Loaded);
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
void AutoCompleteBox_Loaded(object sender, RoutedEventArgs e)
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            Init();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            Init2();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
private void Init()
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// IsDropDownOpen - 是否显示自定完成的下拉框
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
            autoCompleteBox.GotFocus += delegate { autoCompleteBox.IsDropDownOpen = true; };
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            autoCompleteBox.Focus();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            List
<string> collection = new List<string>();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"aabb");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"aabc");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"abcc");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"abbc");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"aaab");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"bcca");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"bbac");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"cbaa");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"ccaa");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"cccb");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"cccc");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"cabc");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            collection.Add(
"cabb");
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            autoCompleteBox.ItemsSource 
= collection;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
/*
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager             * ItemFilter - 过滤下拉框内的对象
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager             * TextFilter - 过滤下拉框内的字符串
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager             * SearchText - 以此值为参数,过滤下拉框中的数据
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager             * SelectedItem - 下拉框当前所选中的对象
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager             
*/

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// 自定义 FilterMode
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// 第一个参数:用户输入的值;第二个参数:下拉框中的对象
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
            autoCompleteBox.ItemFilter += (search, value) =>
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
if (value.ToString().ToLower().StartsWith(search.ToLower()) || value.ToString().ToLower().EndsWith(search.ToLower()))
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
return true;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
return false;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            }
;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
private void Init2()
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            List
<EmployeeModel> employees = new List<EmployeeModel>();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "aabb", DateOfBirty = DateTime.Now, Salary = 111 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "aabc", DateOfBirty = DateTime.Now, Salary = 112 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "abcc", DateOfBirty = DateTime.Now, Salary = 113 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "abbc", DateOfBirty = DateTime.Now, Salary = 114 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "aaab", DateOfBirty = DateTime.Now, Salary = 115 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "bcca", DateOfBirty = DateTime.Now, Salary = 116 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "bbac", DateOfBirty = DateTime.Now, Salary = 117 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "cbaa", DateOfBirty = DateTime.Now, Salary = 118 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "ccaa", DateOfBirty = DateTime.Now, Salary = 119 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "cccb", DateOfBirty = DateTime.Now, Salary = 1111 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "cccc", DateOfBirty = DateTime.Now, Salary = 1112 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "cabc", DateOfBirty = DateTime.Now, Salary = 1113 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            employees.Add(
new EmployeeModel { Name = "cabb", DateOfBirty = DateTime.Now, Salary = 1114 });
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            autoCompleteBoxTemplate.ItemsSource 
= employees;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
/// <summary>
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
/// 演示如何实现按需加载下拉框的数据
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
/// </summary>

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        private void autoCompleteBoxPopulate_Populating(object sender, PopulatingEventArgs e)
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// Populate 是异步的,调用服务也是异步的
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// 所以要先在 Populating 中 Cancel 掉 Populate,以便异步调用服务
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// 服务返回结果后再调用 PopulateComplete() 方法,以便触发 Populated 事件
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            e.Cancel 
= true;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            List
<string> names = new List<string>();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            Uri uri 
= new Uri("http://localhost:8616/Employee.svc/names/" + e.Parameter, UriKind.Absolute);
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            WebClient client 
= new WebClient();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            client.DownloadStringCompleted 
+= (s, args) =>
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
if (args.Error != null)
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    MessageBox.Show(
"调用服务出错" + args.Error.ToString());
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                    
return;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                XDocument xml 
= XDocument.Parse(args.Result);
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                XNamespace ns 
= "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                autoCompleteBoxPopulate.ItemsSource 
= xml.Root.Elements(ns + "string").Select(p => p.Value).ToList();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                autoCompleteBoxPopulate.PopulateComplete();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            }
;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            client.DownloadStringAsync(uri);
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager}

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager


2、演示 DataPager
DataPager.xaml
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager< navigation:Page  xmlns:data ="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"   x:Class ="Silverlight30.Control.DataPager"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           mc:Ignorable
="d"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           xmlns:navigation
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           d:DesignWidth
="640"  d:DesignHeight ="480"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager           Title
="DataPager Page" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
< Grid  x:Name ="LayoutRoot" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
< StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
<!--
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                PageSize - 页大小
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                NumericButtonCount - 数字分页按钮的数量
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                AutoEllipsis - 当页总数大于分页按钮的数量时,是否自动显示省略号
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                IsTotalItemCountFixed - 数据量是否是不变的(即是否没有对当前绑定数据的添加/删除操作)
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                DisplayMode - 分页控件的显示模式 [System.Windows.Controls.Data.PagerDisplayMode 枚举]
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
-->
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
< StackPanel  Margin ="10"   >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
< data:DataPager  x:Name ="dataPager"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            PageSize
="6"  NumericButtonCount ="10"  AutoEllipsis ="True"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            DisplayMode
="FirstLastPreviousNext"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            IsTotalItemCountFixed
="True" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
</ data:DataPager >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
< ListBox  x:Name ="listBox"   />
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
< data:DataPager  x:Name ="dataPager2"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            PageSize
="6"  NumericButtonCount ="10"  AutoEllipsis ="True"
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            DisplayMode
="FirstLastPreviousNextNumeric"  
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                            IsTotalItemCountFixed
="True" >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                
</ data:DataPager >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
</ StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
</ StackPanel >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
</ Grid >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
</ navigation:Page >
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager

DataPager.xaml.cs
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPagerusing  System;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Collections.Generic;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Linq;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Net;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Controls;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Documents;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Input;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Media;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Media.Animation;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Shapes;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Navigation;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Windows.Data;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
using  System.Xml.Linq;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
namespace  Silverlight30.Control
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
public partial class DataPager : Page
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
public DataPager()
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            InitializeComponent();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
this.Loaded += new RoutedEventHandler(DataPager_Loaded);
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
void DataPager_Loaded(object sender, RoutedEventArgs e)
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            Init();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
void Init()
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            List
<string> items = new List<string>();
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
for (int i = 0; i < 100; i++)
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
{
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager                items.Add(i.ToString().PadLeft(
10'0'));
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// PagedCollectionView - 使一个 IEnumerable 集合具有分页功能
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
            PagedCollectionView view = new PagedCollectionView(items);
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            
// 设置 DataPager 的 Source 属性 和 对应的显示数据的控件的 ItemsSource 属性 为同一个 PagedCollectionView 对象
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
            dataPager.Source = view;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            dataPager2.Source 
= view;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager            listBox.ItemsSource 
= view;
稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager        }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager    }

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager}

稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager


OK
[源码下载]