I was looking some tutorials on how to create custom controls in WinRT, and I have a question.
Let\'s say I want to create a simple control that contains some stuff,
Creating a user control is a lot simpler than creating a custom control. For starters a user control has designer support. The disadvantage of a user control is that it is limited in comparison with a custom control.
A user control is excellent if you want to create a control that is a composition of some other controls like in your example but suppose you want to create a special kind of panel, then you really have to create a custom control.
So in summary user control for 'simple' controls user control for complex controls. Any user control can be created by a custom control but not the other way around.
TLDR
A custom (templated) control allows an app to use the Template property to replace the control’s internal element tree. If you don’t need/want your control to have that re-templating feature, then use a UserControl as it’s easier.
UserControl
UserControl
is a lot easier to create with Visual Studio or Blend giving you a decent design view support.Such view is often backed with a corresponding view model if you choose to adopt the MVVM pattern.
One problem with a UserControl
is that while you can reuse it in multiple places in your app - it is difficult to make slight adjustments to the way it looks or behave in different places in your app since it doesn't use templates and the UI tree is loaded in the constructor.
Custom control
custom control
or in some cases templated control
is best suited for a small chunk of UI that serves a single purpose - it visualizes a single, specific type of information.Button
, ToggleButton
, ContentControl
, Slider
, TextBox
or ListView
to add to or override its logic. There are cases though when it makes sense to make one from scratch, subclassing "virtually abstract" Control
, ItemsControl
, RangeBase
, Shape
or even FrameworkElement
(the last two are not templated).Collapsed
to Visible
which allows to defer loading parts of your UI to get performance improvements.Custom panel
A custom panel
is yet another type of UI element that allows to customize how it lays out its children.