Solved

WPF: User Controls vs Control Templates

Posted on 2009-05-08
3
943 Views
Last Modified: 2013-11-12
I am trying to figure out what the main difference is between a User Control and a Control Template.  It seems that in both cases I can specify what controls I want to use since the Control Template allows me to change the entire visual tree of the control I am templating, but the User Control allows me to define what controls I want to include as well.  What is the main difference here?
0
Comment
Question by:AdamEscobedo
3 Comments
 

Assisted Solution

by:lulu2005
lulu2005 earned 20 total points
ID: 24337726
Two things comes up into my mind is:

The user control can
  • let you define your own events and where and how to trigger it.
  • let you define the interactions among the controls.
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 24337845
I agree with lulu. You can do more with a user control, since you're defining not only a group of controls (potentially), but also the code behind, including event handling, etc.

The biggest factor in deciding to make a UC, though, is whether you're going to reuse it. There's little sense, IMO, in creating a user control for one time use.
0
 
LVL 1

Accepted Solution

by:
aweilee earned 30 total points
ID: 24345469
The main difference between user controls and templates is that using a template you can completely change an existing control throughout your application without even needing to change anything else than App.xam. Imagine turning all of the ComboBox controls into spinning 3D carousels: you can do exactly this with templates by modifying just the App.xaml file.

Creating a user controls that would be used in place of your ComboBox, in the above example, means you would need to replace every occurrence of the ComboBox control with a declaration of your user control everywhere. While this can be acceptable for an application that's under development, you definitely don't want to do this in an already developed application.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question