Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The primary difference between these two things, is that the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx" rel="nofollow noreferrer">ControlTemplate</a> defines the look of the control. It is not actually placing content inside of it. At some location inside the content control, there should be some form of <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter.aspx" rel="nofollow noreferrer">ContentPresenter</a>. The built in controls are capable of this because they are what is known as <a href="http://www.devx.com/dotnet/Article/34564" rel="nofollow noreferrer">'lookless controls'</a>, and any custom controls created should also be lookless. When a control is not templated in a lookless manner but instead has a static layout, then the confusion you have run into can occur. </p> <p>As for the <em>correct</em> way to do things, it depends on what you are trying to achieve. If you are attempting to change the control, such as the look and feel or the behavior, then <a href="http://blah.winsmarts.com/2007-2-WPF__ControlTemplate_-_Completely_Swapping_the_UI_of_an_Element.aspx" rel="nofollow noreferrer">using a ControlTemplate</a>, (or DataTemplate, depending on what you are templating), is definitely the way to go. A good example of this is the CheckBox, belive it or not, the CheckBox is actually a ToggleButton (<a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.checkbox.aspx" rel="nofollow noreferrer">more or less</a>), that <a href="http://msdn.microsoft.com/en-us/library/ms752319.aspx" rel="nofollow noreferrer">through templating</a> displays the togleablity in a bullet. <a href="http://msdn.microsoft.com/en-us/magazine/cc163497.aspx" rel="nofollow noreferrer">Here's</a> another very good example of how you can use Templates to do some very nifty things.<br/> </p> <p>ControlTemplates should also be <a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx" rel="nofollow noreferrer">applied through Styles</a>, instead of directly set on an element.</p> <p>If you aren't actually aiming to modify the behavior or look of the control then using the content model is the correct approach.</p> <p><a href="http://designerslove.net/?p=168" rel="nofollow noreferrer">WPF does this better then Silverlight</a>, though I don't know if there are improvements in SL3.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload