Recommended Practices for WPF Custom Control Developers
I have always found that there isn’t enough documentation about Custom Control development in WPF. Most of the information is segregated into articles, blog entries and posts on the WPF Forums. In order to save the trouble for other fellow WPF developers I intend to document all my findings at one place: this blog. To start with, there are some articles which are a must read for all control developers:
- Control Authoring Overview
- Kevin Moore’s article on ColorPicker control
- Creating lookless control
- Control Styling Guidelines [Update: Added link]
Below are some of the practices which I found useful when creating my own custom controls.
Event-handling practices:
- Use RoutedEvents, Commands and CommandManager
- Use TemplatePartAttribute
- Name the controls that are used inside the custom control with something like “PART_SubControlName”. The PART_ prefix is a convention.
- This is useful if you want your control to be styled using a Designer. I am not aware of the exact semantics of how this is used.
- Specify the TemplatePartAttribute for the custom control class
- Override OnApplyTemplate() and check for existence of the subcontrols in use. Check using the GetTemplateChild() method. If a part by that name is absent, throw an exception.
- Attach event handlers on the sub control
Theming practices:
- Create a ResourceDictionary called generic.xaml. Create a folder named themes in your library and put generic.xaml inside that.
- Organize multiple resources using MergedDictionaries [Article]
- Override the DefaultStyleKeyProperty inside the custom controls static constructor.
- Use ComponentResourceKey on specific resources used within the custom control. It is used to embed resources as part of the control.
I will make more posts as I learn about other practices. I am open to feedback from other developers. In future posts I should have more information about Databinding, Localizationpractices.
Recommended Practices for WPF Custom Control Developers的更多相关文章
- ClassLibary和WPF User Control LIbary和WPF Custom Control Libary的异同
说来惭愧,接触WPF这么长时间了,今天在写自定义控件时遇到一个问题:运行界面中并没有显示自定义控件,经调试发现原来没有加载Themes中的Generic.xaml. 可是为什么在其他solution中 ...
- wpf custom control
最近在做WPF,记录一下自定义控件的制作过程,源码请点击:源码. 1.目标 实现一个如图所示的可增减的数字框: 2.先画Template 可以在Generic.xaml中画,也可以用MergedDic ...
- [WPF] 将普通的Library工程,改造成WPF Custom Control 的Library
1. 添加References PresentationCore PresentationFramework System.Xaml WindowsBase2. 修改AssemblyInfo.xsus ...
- Hosting custom WPF calendar control in AX 2012
原作者: https://community.dynamics.com/ax/b/axilicious/archive/2013/05/20/hosting-custom-wpf-calendar-c ...
- Writing a Reusable Custom Control in WPF
In my previous post, I have already defined how you can inherit from an existing control and define ...
- WPF中的Generic.xaml, theme以及custom control
原文:WPF中的Generic.xaml, theme以及custom control 在Visual Studio中创建自定义控件时,所有控件都将添加到/Themes/Generic.xaml. 最 ...
- .NET Core学习笔记(2)—— WPF使用UWP Custom Control
自.NET Core 3.0开始,某软加入了对WPF的支持.同时对XAML Islands也做了进一步加强.在.NET Core 3.0之前,我们只能在WPF程序中,通过两种方式有限制地使用Stand ...
- Tutorial: WPF User Control for AX2012
原作者: https://community.dynamics.com/ax/b/goshoom/archive/2011/10/06/tutorial-wpf-user-control-for-ax ...
- WinForm中Component Class、User Control及Custom Control的区别和使用建议
reference: http://blog.csdn.net/redstonehe/article/details/1536549 .NET Framework 为您提供了开发和实现新控件的能力.除 ...
随机推荐
- 机器学习算法实现解析——word2vec源代码解析
在阅读本文之前,建议首先阅读"简单易学的机器学习算法--word2vec的算法原理"(眼下还没公布).掌握例如以下的几个概念: 什么是统计语言模型 神经概率语言模型的网络结构 CB ...
- CCShatteredTiles3D
CCSprite* pImgBg = CCSprite::create("1.png"); pImgBg->setPosition(ccp(CCDirector::share ...
- 服务器搭建3 安装libevent2.0.20
1.检测是否安装 安装了的话应该是这样的:如果不是,那就装一下. root@iZ23nyl8frqZ:/home/upload# ls -a /usr/lib |grep libeventlibeve ...
- 每日英语:Six Ways to Modernize Your Car
AS AUTO MAKERS ADD far-out features to the latest cars at warp speed--everything from futuristic hea ...
- 每日英语:South India's Streetside Coffee Culture
Early one morning last week I queued outside Sri Gopi Iyengar Coffee and Tiffin Center, a coffee bar ...
- 将本地代码同步到远程github上
1.在本地文件夹下建立.gitignore文件,将github下的github/gitignore/Node.gitignore文件复制到.gitignore中: 2.执行命令git add . 3. ...
- SQL 迭代查询语句
SQL迭代查询 PL/SQL with ORG_Tree(ObjectId,parentID) as ( select a.ObjectId,a.parentID from Ot_Organizati ...
- S3C2440的七种模式之——未定义模式(去掉bl print1 bug解决)
现在做第一个实验,模拟未定义模式. 未定义模式,是cpu遇到自己不能识别的指令时候做出的异常处理. arm指令的机器码一定是按照某种规范要求的,不然你随意写一条指令,cpu不是都可以执行吗?在cpu没 ...
- easyui扩展
datagrid行内编辑时为datetimebox $.extend($.fn.datagrid.defaults.editors, { datetimebox: {// datetimebox就是你 ...
- django 事务错误 -- Transaction managed block ended with pending COMMIT/ROLLBACK
Request Method: GET Request URL: http://192.168.128.111:8000/×××/××××/ Django Version: 1.4.8 Excepti ...