Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF User Controls vs Custom Controls

Tags:

I am trying to creating a combobox with checkboxes on each line to allow multiple selecting. Would this be better as a User Control or Custom Control?

I haven't created a control before so just looking for a little advice on what direction I need to head.

Thanks.

like image 573
Darren Young Avatar asked Jun 08 '11 13:06

Darren Young


People also ask

What is the difference between custom controls and 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.

What are user controls and custom controls?

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.

What is a WPF user control?

User controls, in WPF represented by the UserControl class, is the concept of grouping markup and code into a reusable container, so that the same interface, with the same functionality, can be used in several different places and even across several applications.

What is the purpose of user control?

The purpose of a UserControl is to group a set of controls into one, reusable component. They cannot be styled or templated. The purpose of a Custom Control is to extend an existing control, or to create a brand new control.


2 Answers

I would say use a datatemplate.

Like this: Looking for a WPF ComboBox with checkboxes

It's a lot more simple than trying to create your own control. :)

like image 40
Ashley Grenon Avatar answered Oct 29 '22 07:10

Ashley Grenon


UserControl (Composition)

  • Composes multiple existing controls into a reusable "group"
  • Consists of a XAML and a code behind file
  • Cannot be styled/templated
  • Derives from UserControl

CustomControl (Extending an existing control)

  • Extends an existing control with additional features
  • Consists of a code file and a default style in Themes/Generic.xaml
  • Can be styled/templated
  • The best approach to build a control library

In your case, I think UserControl would be better; here's an example for you:

<CheckBox Content="Property" IsChecked="{Binding Path=SomeProperty}" />
<ComboBox IsEnabled="{Binding Path=Enabled}" />
like image 131
Irvin Dua Avatar answered Oct 29 '22 09:10

Irvin Dua