What is Custom Control?
A custom control is a loosely coupled control defined in a class, which derives from Control. The UI of custom control generally defined in a Resource Dictionary inside the resource file. We can create themes for custom control and reuse them in various projects very easily.
Button, CheckBox, TextBox etc. even a UserControl is nothing but a Custom Control. You can easily load them inside a XAML page.
A Custom control generally inherits from System.Windows.Controls.Control class. You may derive from a different custom control also depending on your requirement.
Custom Controls are compiled into a dll assembly and can be reused in multiple places very easily. You have total control over it's code, thus gives you more flexibility to extend the
behaviour. Once you build and add reference of custom control in your project, you can find it in the toolbox. Thus, you will be able to drag and drop the control in your design view and start working with that very easily.What is User Control?
The base "UserControl" is nothing but a Custom Control that you derive to create control UI specific to your project. Generally we create a UserControl which placed inside a XAML page with tightly bonding to it's code behind. You can directly access it's UI elements from code behind and do some specific operations.
A custom UserControl inherits from System.Windows.Controls.UserControls class, which inherits from base "Control" class.
You can't create theming support for UserControls but can style them by creating theme for it's child Custom Controls because they represents a collection of controls. Once you create a UserControl UI in once project, you can't change them in the other projects.
Difference between CustomControl and UserControl
So, now you got the difference between Custom Control and User Control, I guess. Let's summarize the difference again. Read the comparison below to make it clear:
Custom Control | User Control |
A loosly coupled control w.r.t code and UI | A tightly coupled control w.r.t code and UI |
Derives from Control | Derives from UserControl |
Defines UI in the ResourceDictionary | Defines UI as a normal XAML |
UI can be skinable | Child controls can skinable only |
Has Dynamic layout | Has static layout |
UI can be changed in different project | UI is fixed and can't have different look in every project |
Has full toolbox support | Can't be added to the toolbox |
Defines a single control | Defines a set of controls |
More flexible | Not much flexible like Custom Control |
Requires in depth knowledge of Silverlight UI Model | Does not require depth knowledge of UI Model |
Hope, you got a better understanding now from the above comparison table.ç
No comments:
Post a Comment