?
Solved

templates in silverlight

Posted on 2008-06-20
6
Medium Priority
?
245 Views
Last Modified: 2013-11-12
Hi,

Can someone clarify what templates are in silverlight .net  as I am getting confused with what i have got.
These 3 objects do what

ContentTemplate property
ContentControl
 DataTemplate.
0
Comment
Question by:jagguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:adler77
ID: 21836345
Templates are used to help when you want to skin and reuse controls. A ControlTemplate is defined in XAML as a resource so that your control can style itself based on that template. For instance, I needed a tab-type control in beta 1, and since there wasn't a tab control yet, I used a template to make radio buttons look like tabs. All I had to do was write some XAML to make it look the way I wanted, and Silverlight handled the rest because internally, since they were radio buttons, I still had access to all of the methods and events that radio buttons get. If I clicked on one tab, the others would automatically become disabled, and so forth.

DataTemplate/ItemTemplate is very useful for controls that access data, like DataGrid or ListBox. Inside your control (lets say ListBox) you would create an ItemTemplate and define how you want things to look for one item. You could databind an image URI to an Image control, a name field to a TextBlock, and add a "Delete" button all at once, and then Silverlight will use that template for as many items that get bound to that list.

For a great example of the DataTemplate/ItemTemplate see ScottGu's Digg example (http://weblogs.asp.net/scottgu/archive/2008/02/22/first-look-at-silverlight-2.aspx). It was made for beta 1, though, so it may not build anymore with beta 2 but at least his tutorial and code will go a long way. For great info on styling controls, see Karen Corby's blog. Start here (http://scorbs.com/2008/06/11/parts-states-model-with-visualstatemanager-part-1-of/) if you like.
0
 

Author Comment

by:jagguy
ID: 21836401
thankyou I  will look over what you said
0
 

Author Comment

by:jagguy
ID: 21845676
I am not understanding how to use contentControl or why you need it. Why have it?

You can display data styled is that the idea?

 It is hard finding a simple example  on this but can someone give me a small code snipper to see it working in .net?
0
 
LVL 8

Accepted Solution

by:
adler77 earned 2000 total points
ID: 21862313
The page for it is here: http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol(VS.95).aspx

Really, it has little to no use when building a Silverlight project. It is a base class that other controls are built from, so you generally use them instead. You probably wouldn't ever use a ContentControl itself.
0
 

Author Comment

by:jagguy
ID: 21864192
i guess if  i was to build my own controls then i see a use but your right , I mean why bother having this control in silverlight?
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

719 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