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 为您提供了开发和实现新控件的能力.除 ...
随机推荐
- 程序包org.junit不存在和编码GBK的不可映射字符问题解决
maven项目在打包编译时提示: 解决办法: 将pom中junit依赖中的scope给注释掉 <dependency> <groupId>junit</groupId&g ...
- Linux 索引节点(inode)详解
参考文章:http://www.ruanyifeng.com/blog/2011/12/inode.html
- java.util.Date和java.sql.Date 一点区别
最近无意中发现,在oracle中同一样的一个Date类型字段,存储的日期格式有两种不同的情况,第一种是2011-1-1 12:00:00,第二种是2011-1-1,仔细查找发现在向数据库中写数据的时候 ...
- mingw环境添加mysql开发库
今天碰巧要用到mysql进行开发,在windows的mingw平台. 0.下载mysql http://cdn.mysql.com/Downloads/MySQL-5.1/mysql-noinstal ...
- CSAPP 读书笔记 - 2.31练习题
根据等式(2-14) 假如w = 4 数值范围在-8 ~ 7之间 2^w = 16 x = 5, y = 4的情况下面 x + y = 9 >=2 ^(w-1) 属于第一种情况 sum = x ...
- postgresql 修改字段名称
ALTER TABLE auth_user RENAME email TO aemail;
- Python os.popen() 方法
简述 就是新建一个管道执行一个命令. 方法是os.popen(命令,权限,缓冲大小) 比如 a = 'mkdir def' b = os.popen(a,) print b 就是等同于使用命令去创建了 ...
- 纯真ip导入mysql
先从纯真官网右侧下载ip数据库 更新后,点击解压,可以把数据库保存为txt格式 格式化数据 ip格式如下图 可见并不是很规范,而且最底部字段数也不一致 先用正则表达式,查找替换一下 (\d+.\d+. ...
- python 数据工程 and 开发工具Sublime
数据工程采集.存储.清洗.分析.可视化 编程语言C++和Javapython大法Rweb:php.html.css.javascript 结合采集:python存储:python+数据库/.csv/t ...
- Linux 下Tomcat服务器响应越来越慢分分析
本文转自自:https://www.cnblogs.com/yangc/p/6859985.html ,感谢给我提供提供思路. 服务器响应慢的分析与解决(Linux服务器) 一.分析思路 1.排除本机 ...