Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use UserControl vs. Control in Silverlight?

I'm just getting my feet wet in Silverlight, and don't really understand the differences and pros/cons of creating a UserControl vs. creating a Control for the same task (as in when you right click on a selection in Expression Blend, for instance).

It seems like selecting "Make Into Control" just creates a new template for the base type you specify, whereas creating a UserControl creates a whole new base class. Is that correct?

In this particular instance, I'm creating a custom text box control that only takes numbers, and divides itself into 3 sections, storing 3 values into separate properties as pictured below. In this particular case, which would be best?

like image 813
Dov Avatar asked Dec 17 '09 17:12

Dov


1 Answers

UserControls are meant to be a composite control - basically a bunch of other "controls" grouped together to work as a single, cohesive unit.

Custom Controls, on the other hand, are intended to be used as a single control. Think of the basic controls in the framework, such as TextBox or Button - if you were implementing something like that, you'd want a Control. (This is less common than UserControls, especially in WPF, since you can use templating on base class controls to accomplish quite a few things where you'd need custom controls in other frameworks). A custom Control is all about defining new behavior for a single "control."

like image 187
Reed Copsey Avatar answered Sep 21 '22 15:09

Reed Copsey