WPF自定義分頁控制項,樣式自定義,簡單易用

2022-01-23 16:32:58 字數 3888 閱讀 8477

做了許久伸手黨,終於有機會貢獻一波,搜尋一下wpf分頁控制項,還是多,但是不太通用,主要就是樣式問題,這個wpf很好解決,還有乙個就是分頁控制項嘛,只關心幾個數字的變動就行了,把頁碼改變事件暴露出來,資料的載入在這裡就做就行,所以這個分頁控制項很簡單...

好像也沒啥講的,直接上**了

分頁控制項基本樣式

分頁控制項**

[templatepart(name = "part_totalcount", type = typeof(textblock))]

[templatepart(name = "part_pagesize", type = typeof(textblock))]

[templatepart(name = "part_pageindex", type = typeof(textblock))]

[templatepart(name = "part_totalpage", type = typeof(textblock))]

[templatepart(name = "part_firstpage", type = typeof(button))]

[templatepart(name = "part_prepage", type = typeof(button))]

[templatepart(name = "part_nextpage", type = typeof(button))]

[templatepart(name = "part_lastpage", type = typeof(button))]

[templatepart(name = "part_pagego", type = typeof(button))]

[templatepart(name = "part_pagenum", type = typeof(textbox))]

public class pager : control

#endregion

#region 依賴屬性

#region 總記錄數

public int totalcount

set}

// using a dependencyproperty as the backing store for totalcount. this enables animation, styling, binding, etc...

public static readonly dependencyproperty totalcountproperty =

dependencyproperty.register("totalcount", typeof(int), typeof(pager), new frameworkpropertymetadata(0, frameworkpropertymetadataoptions.bindstwowaybydefault,

(obj, e) =>

));#endregion

#region 每頁大小

public int pagesize

set}

// using a dependencyproperty as the backing store for pagesize. this enables animation, styling, binding, etc...

public static readonly dependencyproperty pagesizeproperty =

dependencyproperty.register("pagesize", typeof(int), typeof(pager), new frameworkpropertymetadata(0,

(obj, e) =>

));#endregion

#region 當前頁

public int pageindex

set}

// using a dependencyproperty as the backing store for pageindex. this enables animation, styling, binding, etc...

public static readonly dependencyproperty pageindexproperty =

dependencyproperty.register("pageindex", typeof(int), typeof(pager), new frameworkpropertymetadata(0,

(obj, e) =>

));#endregion

#region 總頁數

public int totalpage

set}

// using a dependencyproperty as the backing store for totalpage. this enables animation, styling, binding, etc...

public static readonly dependencyproperty totalpageproperty =

dependencyproperty.register("totalpage", typeof(int), typeof(pager), new frameworkpropertymetadata(0,

(obj, e) =>

));#endregion

#endregion

#region 路由事件

public static readonly routedevent pagechangedevent = eventmanager.registerroutedevent("pagechanged",

routingstrategy.bubble, typeof(eventhandler), typeof(pager));

public event eventhandlerpagechanged

remove

}protected virtual void onpagechanged()

#endregion

#region 方法

public void settotalpage(int totalpage)

public void setpageindex(int pageindex)

public void setpagesize(int pagesize)

/// /// 設定總記錄數

///

///

public void settotalcount(int totalcount)

#endregion

#region 私有方法

private void _btnpagego_click(object sender, routedeventargs e)}}

private void _btnlastpage_click(object sender, routedeventargs e)

private void _btnnextpage_click(object sender, routedeventargs e)

}private void _btnprepage_click(object sender, routedeventargs e)

}private void _btnfirstpage_click(object sender, routedeventargs e)

#endregion

}

事件引數 pagechangedeventarg.cs

public class pagechangedeventarg : routedeventargs

public pagechangedeventarg(int pageindex) : base()

}

demo和原始碼都在開源中國上

WPF自定義控制項(四) 自定義控制項

原文 wpf自定義控制項 四 自定義控制項 在實際工作中,wpf提供的控制項並不能完全滿足不同的設計需求。這時,需要我們設計自定義控制項。這裡lz總結一些自己的思路,特性如下 下面舉例說說在專案中我們經常用到調音台音量條,寫乙個自定義控制項模擬調音台音量條。自定義控制項singnallight,實現...

自定義控制項樣式

分三個層次 drawable selector style drawable可以是一張 顏色 xml檔案畫的向量圖。xml向量圖根節點是shape,屬性用來指定形狀,子標籤有solid 填充 corners 圓角 gradient 漸變 padding 間隔 size 大小 stroke 描邊 se...

WPF 自定義按鈕樣式

有了wpf,一切都將變得簡單.樣式 比較多,請看附件 files lovebread buttonstyle.rar controltemplate 指定控制項的可視結構和可視行為。可以通過為控制項指定新 controltemplate 自定義該控制項的外觀。建立 controltemplate 後...