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.
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.
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.
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.
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.
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. :)
UserControl (Composition)
CustomControl (Extending an existing control)
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}" />
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