Published articles on other web sites*

Published articles on other web sites*

difference between Custom Control and User Control

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.
image
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.
image
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 ControlUser Control
A loosly coupled control w.r.t code and UIA tightly coupled control w.r.t code and UI
Derives from ControlDerives from UserControl
Defines UI in the ResourceDictionaryDefines UI as a normal XAML
UI can be skinableChild controls can skinable only
Has Dynamic layoutHas static layout
UI can be changed in different projectUI is fixed and can't have different look in every project
Has full toolbox supportCan't be added to the toolbox
Defines a single controlDefines a set of controls
More flexibleNot much flexible like Custom Control
Requires in depth knowledge of Silverlight UI ModelDoes not require depth knowledge of UI Model
Hope, you got a better understanding now from the above comparison table.ç

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...