I'm working on creating a date/time user control in WPF using C# 2008. My first user control. I'm also using Matthew MacDonald's book, "Pro WPF in C# 2008". In that book he strongly recommended creating a user control using the WPF Custom Control Library project template; so I followed his suggestion. I've finished writing the code which would go into what I think of as the code-behind file. Now I'm ready to write the XAML.
The only problem is, I just discovered there is no corresponding .xaml file? So, I don't get why using a WPF Custom Control Library project is better, or prefered, when writing a user control?
CustomControl is a loosely coupled control w.r.t code and UI while UserControl is a tightly coupled control w.r.t code and UI. When using CustomControl UI can be changed in different projects but for a UserControl UI is fixed and can't have different looks in different project.
A customControl can be styled and templated and best suited for a situation when you are building a Control Library. On the contrary, a UserControl gives you an easy way to define reusable chunk of XAML which can be reused widely in your application and when you don't need to use it as a Control Library .
UserControl : A control which can reuse the Components in the Applications. The control can be defined in both Xaml and Code-Behind. CustomControl : An UserInterface element that have a distinct behavior which is said as CustomControl.
A software routine that adds some enhancement or feature to an application. Custom controls are written to provide as little as a few graphical interface improvements to as much as providing full imaging, spreadsheet and text editing extensions to the application.
A user control and a custom control solve two distinctly different problems.
UserControls are meant to compose multiple WPF controls together, in order to make a set of functionality built out of other controls. This is often used to compose a portion of a window or screen in order to organize your development by allowing you to group multiple pieces of functionality into one "control". For example, if you wanted to make a control for editing a User which provided text boxes for first and last name, age, etc., a single UserControl could be dropped onto a Window and bound to a User instance to edit this. (In this case, you're using standard controls, such as TextBox, to "compose" a control for a more complex purpose.)
A CustomControl, however, is meant to be a new single control. This would typically be a replacement for a built-in control (which could not be redone via templating). I've found that the need for CustomControls is actually fairly rare in WPF, since the WPF templating options and attached properties allow you to do nearly anything with standard controls, once you learn them fully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With