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 为您提供了开发和实现新控件的能力.除 ...
随机推荐
- Umeng社会化组件使用笔记
1.申请umeng账号 2.下载umeng sdk,并且阅读友盟开放文档 3.申请各开放平台的账号,获取appid .appkey.appsecret:注意,这里需要配置安全域名sns.whalecl ...
- 基于ASP.NET MVC的ABP框架入门学习教程
为什么使用ABP 我们近几年陆续开发了一些Web应用和桌面应用,需求或简单或复杂,实现或优雅或丑陋.一个基本的事实是:我们只是积累了一些经验或提高了对,NET的熟悉程度. 随着软件开发经验的不断增加, ...
- angular的uiRouter服务学习(1)
angular有内置的路由服务$route:angular -- $route API翻译 使用$route可以帮助实现路由的切换,视图的改变,但是这个内置的$route只包含了基本的功能,在很多场合 ...
- Android 拍照
android调用camera时,可以自己写一个activity,赋上相关参数,打开前camera就可以了: 需要申请的permission,在AndroidManifest.xml中添加: < ...
- SpringMVC中的 JSR 303 数据校验框架说明
JSR 303 是java为Bean数据合法性校验提供的标准框架,它已经包含在JavaEE 6.0中. JSR 303 通过在Bean属性上标注类似于@NotNull.@Max等标准的注解指定校验规则 ...
- jdango 部署之nginx+uwsgi
1,安装pip sudo apt-get install python-pip 2,利用 pip 安装 Django sudo pip install Django 3,检测Django是否安装成功 ...
- SpringBoot启动和停止脚步
1.start.sh # start.sh 启动项目 #!/bin/sh file="/123/springcloud/admin.jar" if [ -f "$file ...
- 多媒体文件格式之TS
[时间:2016-07] [状态:Open] TS流是MPEG-2标准中定义一种用于直播的码流结构,具有很好的容错能力.所有跟TS相关的标准可以从ISO/IEC_13818-1中找到. 通常TS流的后 ...
- Java自动创建多层文件目录
// 创建文件上传路径 public static void mkdir(String path) { File fd = null; try { fd = new File(path); if (! ...
- Scapy:局域网MAC地址扫描脚本
转载自:http://blog.sina.com.cn/s/blog_4b5039210100gn6k.html 未测试,回头研究研究. 用python+scapy写的,只要双击.py文件即可,扫描当 ...