Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Extract Default Control Template In Visual Studio?

I'm wondering how I can extract (get a copy) of the Default Template of a given control using Visual Studio. I know this can be done with Expression Blend (right click a control, "Edit Template" -> "Edit a Copy...") which then copies the default control template in my Xaml. But can this be done with Visual Studio at all?

like image 429
Shai UI Avatar asked Jan 11 '12 18:01

Shai UI


People also ask

What is the difference between control template and data template?

A ControlTemplate will generally only contain TemplateBinding expressions, binding back to the properties on the control itself, while a DataTemplate will contain standard Binding expressions, binding to the properties of its DataContext (the business/domain object or view model).

What is control template?

The ControlTemplate allows you to specify the visual structure of a control. The control author can define the default ControlTemplate and the application author can override the ControlTemplate to reconstruct the visual structure of the control.

What is control template in WPF?

The ControlTemplate contains the tree of elements that define the desired look. After you define a ControlTemplate you can attach it to any Control or Page by setting it's TemplateProperty. In this example I am also showing you how to use Triggers with ControlTemplate.


1 Answers

2015 update with clear instructions

In Visual Studio 2013, you can get the default ControlTemplate of a control in a few simple steps.

  1. In the WPF designer, select the relevant control, or place the mouse cursor on the relevant control in the XAML.

  2. Press F4 to open the Properties Window.

  3. Open the Miscellaneous category to find the Template property, or type Template in the search field at the top of the Window.

  4. Click on the little square to the right of the Template field and select the Convert to New Resource... option:

enter image description here

  1. In the popup dialog, name the new ControlTemplate to be added and decide where you want it to be defined:

enter image description here

  1. Click on the OK button.

EDIT >>>

In Visual Studio 2019 and later, this option seems to be disabled for some reason. A workaround can be found by right-clicking the control in the design view and selecting "Edit Template", then selecting "Edit a Copy...".

like image 52
Sheridan Avatar answered Oct 10 '22 15:10

Sheridan