开发者

WPF User Controls vs Custom Controls

开发者 https://www.devze.com 2023-03-11 01:58 出处:网络
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 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.


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}" />


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. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消