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 为您提供了开发和实现新控件的能力.除 ...
随机推荐
- Atitit 获取剪贴板内容
Atitit 获取剪贴板内容 1.1. Java当然有这个功能,但是体积大,先使用script语言实现吧..1 1.2. node.js 好像没这个api ...1 1.3. Ahk也没有..Aut ...
- Vivado+FPGA:如何使用Debug Cores(ILA)在线调试(烧录到flash里可以直接启动)
在Vivado下在线调试是利用ILA进行的,Xilinx官方给出了一个视频,演示了如何使用Vivado的debug cores,下面我根据这个官方视频的截图的来演示一下: 官方的视频使用的软件版本为2 ...
- [CoreOS 转载] CoreOS实践指南(一)
转载:http://www.csdn.net/article/2014-12-29/2823356 摘要:CoreOS是一个采用了高度精简的系统内核及外围定制的操作系统.ThoughtWorks的软件 ...
- [SQL in Azure] Windows Azure Virtual Machine Readiness and Capacity Assessment
http://technet.microsoft.com/en-us/solutionaccelerators/dd537566.aspx http://blogs.technet.com/b/map ...
- Recommender Systems中Yehuda Koren 和 Ma Hao的paper
以前读了Yehuda Koren和Ma Hao的论文,感觉非常不错,这里分享一下.如果想着具体了解他们近期发的论文,可以去DBLP去看看. Yehuda Koren也是Netflix Prize的冠军 ...
- Vue2键盘事件
这两天学习了Vue.js 感觉组件这个地方知识点挺多的,而且很重要,所以,今天添加一点小笔记,学习一下Vue键盘事件 键盘事件 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...
- BI--SAP BI的权限管理
源地址 :http://silverw0396.iteye.com/blog/229274 一.sapBI的用户分类 There are different types of users in SAP ...
- 关于构造函数和this调用的思考
文中一系列思考和内容引发自以下问题:我需要在一个类的构造函数中调用另一个对象的构造函数,并使用this初始化其中的一个引用成员. 主要遇到的问题: 1. 构造函数的初始化列表中能访问this吗? 很明 ...
- 【Linux】svn添加用户
1. 找到svn安装路径 /svn/repositories/ (如果不知道,可以搜索 :find / -name svn或者是ps -ef | grep svn) 2.进入该目录的conf,其中包 ...
- How To Install Java with Apt-Get on Ubuntu 16.04
Introduction Java and the JVM (Java's virtual machine) are widely used and required for many kinds o ...