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 为您提供了开发和实现新控件的能力.除 ...
随机推荐
- Javascript的&&和||的另类用法
Javascript的&&和||的另类用法. 又开始研究起 Titanium 来,发现其官方出品的MVC框架(Alloy)还是挺不错的,刚开始苦于没有好的代码来学习,文档又少,所以一直 ...
- PreparedStatement用途
关于PreparedStatement接口,需要重点记住的是:1. PreparedStatement可以写参数化查询,比Statement能获得更好的性能.2. 对于PreparedStatemen ...
- FFmpeg(3)-AVFormatContext 结构体内容分析
AVIOContext *pb IO Context,.自定义一些读写格式或者从内存当中读时用到此成员变量. char filename[1024]; ...
- MonoBehaviour类Invoke, Coroutine
异步函数 在一个方法执行时调用另一个方法.而被调用的方法或者其中的某些语句不是立刻执行,而是过一段时间后才执行. MonoBehaviour提供了两种异步方法 调用(Invoke) 协程(Corout ...
- 理解Netty中的零拷贝(Zero-Copy)机制【转】
理解零拷贝 零拷贝是Netty的重要特性之一,而究竟什么是零拷贝呢? WIKI中对其有如下定义: “Zero-copy” describes computer operations in which ...
- 【Acm】算法之美—Jugs
题目概述:Jugs In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted wi ...
- 【C/C++】C/C++中Static的作用详述
在C语言中,static的字面意思很容易把我们导入歧途,其实它的作用有三条. ❶先来介绍它的第一条也是最重要的一条:隐藏.当我们同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可 ...
- FIDDLER的使用方法及技巧总结(连载三)FIDDLER使用技巧及方法
(接上篇!~~~~) 三.FIDDLER使用技巧及方法 1.AutoResponder选项卡的使用 Fiddler的AutoResponder 选项卡允许你使用本地硬盘的文件来作为返回内容,而不是把请 ...
- SpringBoot 跨域 Access-Control-Allow-Origin 问题
https://blog.csdn.net/taoism_jerry/article/details/79695336 **************************************** ...
- 转:linux下配置JDK提示tools.jar/dt.jar权限不够
原文:http://lkf009.iteye.com/blog/1327912 提示权限不够的原因:CLASSPATH=.;$JAVA_HOME/lib/tools.jar;$JAVA_HOME/li ...