1 public void BtnPageClickEvent(object sender,string focusForeground,string lostFocusForeground)
2 {
3 Button btn = (Button)sender;
4 string btnContent = btn.Content as string;
5 if (btn.Focus())
6 {
7 btn.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(focusForeground));
8 }
9 btn.LostFocus += delegate
10 {
11 btn.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(lostFocusForeground));
12 };
13 switch (btnContent)
14 {
15 case "首页":
16 {
17 PagedHelper.PageIndex = 1;
18 this.DGAlertInfos.ItemsSource = PagedHelper.GetPagedData(AlertLists, 0, PagedHelper.PageSize).ToList();
19 break;
20 }
21 case "上一页":
22 {
23 if (PagedHelper.PageIndex != 1)
24 {
25 PagedHelper.PageIndex--;
26 }
27 if (PagedHelper.PageIndex <= 1)
28 {
29 this.DGAlertInfos.ItemsSource = PagedHelper.GetPagedData(AlertLists, 0, PagedHelper.PageSize).ToList(); ;
30 }
31 else
32 {
33 this.DGAlertInfos.ItemsSource = PagedHelper.GetPagedData(AlertLists, (PagedHelper.PageIndex - 1) * PagedHelper.PageSize, PagedHelper.PageSize).ToList();
34 }
35 break;
36 }
37 case "下一页":
38 {
39 if (PagedHelper.PageIndex != PagedHelper.PageCount)
40 {
41 PagedHelper.PageIndex++;
42 }
43 if (PagedHelper.PageIndex >= PagedHelper.PageCount)
44 {
45
46 this.DGAlertInfos.ItemsSource = PagedHelper.GetPagedData(AlertLists, PagedHelper.PageSize * (PagedHelper.PageCount - 1), PagedHelper.PageSize).ToList();
47 }
48 else
49 {
50 this.DGAlertInfos.ItemsSource = PagedHelper.GetPagedData(AlertLists, (PagedHelper.PageIndex - 1) * 10, PagedHelper.PageSize).ToList();
51 }
52 break;
53 }
54 case "尾页":
55 {
56 PagedHelper.PageIndex = PagedHelper.PageCount;
57 this.DGAlertInfos.ItemsSource = PagedHelper.GetPagedData(AlertLists, PagedHelper.PageSize * (PagedHelper.PageCount - 1), PagedHelper.PageSize).ToList();
58 break;
59 }
60 default:
61 {
62
63 break;
64 }
65 }
66 }
使用:
1 private void BtnPageClick(object sender, RoutedEventArgs e)
2 {
3 BtnPageClickEvent(sender, "#007CF1", "#4D4D4D");
4 }