-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathControlTemplate.xml
370 lines (318 loc) · 22.8 KB
/
ControlTemplate.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<Type Name="ControlTemplate" FullName="System.Windows.Controls.ControlTemplate">
<TypeSignature Language="C#" Value="public class ControlTemplate : System.Windows.FrameworkTemplate" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit ControlTemplate extends System.Windows.FrameworkTemplate" />
<TypeSignature Language="DocId" Value="T:System.Windows.Controls.ControlTemplate" />
<TypeSignature Language="VB.NET" Value="Public Class ControlTemplate
Inherits FrameworkTemplate" />
<TypeSignature Language="F#" Value="type ControlTemplate = class
 inherit FrameworkTemplate" />
<TypeSignature Language="C++ CLI" Value="public ref class ControlTemplate : System::Windows::FrameworkTemplate" />
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Windows.FrameworkTemplate</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]</AttributeName>
<AttributeName Language="F#">[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]</AttributeName>
</Attribute>
<Attribute>
<AttributeName Language="C#">[System.Windows.Markup.DictionaryKeyProperty("TargetType")]</AttributeName>
<AttributeName Language="F#">[<System.Windows.Markup.DictionaryKeyProperty("TargetType")>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Specifies the visual structure and behavioral aspects of a <see cref="T:System.Windows.Controls.Control" /> that can be shared across multiple instances of the control.</summary>
<remarks>
<format type="text/markdown">< topic for examples and an in-depth discussion.
If you are writing your own control, see "Create a Custom Control" in the [Control Authoring Overview](/dotnet/framework/wpf/controls/control-authoring-overview).
A <xref:System.Windows.Controls.ControlTemplate> is intended to be a self-contained unit of implementation detail that is invisible to outside users and objects, including styles. The only way to manipulate the content of the control template is from within the same control template.
<a name="xamlObjectElementUsage_VisualTree"></a>
## XAML Property Element Usage
```xaml
<ControlTemplate>
<VisualTreeRootNode>
VisualTreeNodeContents
</VisualTreeRootNode>
</ControlTemplate>
```
<a name="xamlValues_VisualTree"></a>
## XAML Values
*ControlTemplate*
Object element for <xref:System.Windows.Controls.ControlTemplate> or a derived class.
*VisualTreeRootNode*
A single XAML element as the immediate child of the <xref:System.Windows.Controls.ControlTemplate> (or a derived class). Templates must have a single root node. In order to generate a useful template, the element chosen as *VisualTreeRootNode* is expected to support a content model of its own, often a model that supports multiple child elements.
*VisualTreeNodeContents*
One or more elements that complete the intended template. If the element chosen as *VisualTreeRootNode* only supports a single child, then there can only be one element declared as *VisualTreeNodeContents*. It is also possible (though uncommon) to provide text content if the chosen *VisualTreeRootNode* supports a text content property.
## Examples
The following shows a <xref:System.Windows.Controls.Button> <xref:System.Windows.Style> that sets the <xref:System.Windows.Controls.ControlTemplate> of a <xref:System.Windows.Controls.Button>:
:::code language="xaml" source="~/snippets/csharp/System.Windows.Controls/ContentPresenter/Overview/Window1.xaml" id="Snippetbuttonct":::
When this gets applied, the <xref:System.Windows.Controls.Button> appears as an <xref:System.Windows.Shapes.Ellipse>:

When you set the <xref:System.Windows.Controls.Control.Template%2A> property of a <xref:System.Windows.Controls.Control> to a new <xref:System.Windows.Controls.ControlTemplate> as in the above example, you are replacing the entire template. What the <xref:System.Windows.Controls.Button> looks like when it is in focus or pressed is all part of the default appearance of the button that you are replacing. Therefore, depending on your needs, you may want to put in your definition what your button should look like when it is pressed, and so on, as in the following example:
:::code language="xaml" source="~/snippets/csharp/System.Windows/TemplateBindingExtension/Overview/button.xaml" id="Snippet1":::
Note that this example references resources that are not shown here. For the complete sample, see [Styling with ControlTemplates Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Styles%20&%20Templates/IntroToStylingAndTemplating). That sample provides examples of control templates for many controls and is the best way for you to get started with creating control templates.
]]></format>
</remarks>
<altmember cref="T:System.Windows.Style" />
<altmember cref="T:System.Windows.DataTemplate" />
<altmember cref="T:System.Windows.Controls.ContentPresenter" />
<altmember cref="T:System.Windows.Controls.ItemsPresenter" />
<altmember cref="T:System.Windows.TemplateBindingExtension" />
<altmember cref="P:System.Windows.FrameworkElement.OverridesDefaultStyle" />
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Windows.Controls.ControlTemplate" /> class.</summary>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public ControlTemplate ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Controls.ControlTemplate.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 ControlTemplate();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Windows.Controls.ControlTemplate" /> class.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public ControlTemplate (Type targetType);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(class System.Type targetType) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Controls.ControlTemplate.#ctor(System.Type)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (targetType As Type)" />
<MemberSignature Language="F#" Value="new System.Windows.Controls.ControlTemplate : Type -> System.Windows.Controls.ControlTemplate" Usage="new System.Windows.Controls.ControlTemplate targetType" />
<MemberSignature Language="C++ CLI" Value="public:
 ControlTemplate(Type ^ targetType);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="targetType" Type="System.Type" />
</Parameters>
<Docs>
<param name="targetType">The type this template is intended for.</param>
<summary>Initializes a new instance of the <see cref="T:System.Windows.Controls.ControlTemplate" /> class with the specified target type.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="TargetType">
<MemberSignature Language="C#" Value="public Type TargetType { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Type TargetType" />
<MemberSignature Language="DocId" Value="P:System.Windows.Controls.ControlTemplate.TargetType" />
<MemberSignature Language="VB.NET" Value="Public Property TargetType As Type" />
<MemberSignature Language="F#" Value="member this.TargetType : Type with get, set" Usage="System.Windows.Controls.ControlTemplate.TargetType" />
<MemberSignature Language="C++ CLI" Value="public:
 property Type ^ TargetType { Type ^ get(); void set(Type ^ value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.ComponentModel.DefaultValue(null)]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DefaultValue(null)>]</AttributeName>
</Attribute>
<Attribute>
<AttributeName Language="C#">[System.Windows.Markup.Ambient]</AttributeName>
<AttributeName Language="F#">[<System.Windows.Markup.Ambient>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Type</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the type for which this <see cref="T:System.Windows.Controls.ControlTemplate" /> is intended.</summary>
<value>The default value is <see langword="null" />.</value>
<remarks>
<format type="text/markdown"><.
## Examples
The following example demonstrates the use of this property:
:::code language="xaml" source="~/snippets/csharp/System.Windows/TemplateBindingExtension/Overview/label.xaml" id="Snippetlabel":::
The above example uses the following resource:
For the complete sample, see [Styling with ControlTemplates Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Styles%20&%20Templates/IntroToStylingAndTemplating).
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The <see cref="P:System.Windows.Controls.ControlTemplate.TargetType" /> property must not be <see langword="null" /> if the definition of the template has a <see cref="T:System.Windows.Controls.ContentPresenter" />.</exception>
<exception cref="T:System.ArgumentException">The specified types are not valid. The <see cref="P:System.Windows.Controls.ControlTemplate.TargetType" /> of a <see cref="T:System.Windows.Controls.ControlTemplate" /> must be or inherit from a <see cref="T:System.Windows.Controls.Control" />, a <see cref="T:System.Windows.Controls.Page" />, or a <see cref="T:System.Windows.Navigation.PageFunctionBase" />.</exception>
</Docs>
</Member>
<Member MemberName="Triggers">
<MemberSignature Language="C#" Value="public System.Windows.TriggerCollection Triggers { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Windows.TriggerCollection Triggers" />
<MemberSignature Language="DocId" Value="P:System.Windows.Controls.ControlTemplate.Triggers" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Triggers As TriggerCollection" />
<MemberSignature Language="F#" Value="member this.Triggers : System.Windows.TriggerCollection" Usage="System.Windows.Controls.ControlTemplate.Triggers" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::Windows::TriggerCollection ^ Triggers { System::Windows::TriggerCollection ^ get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;windowsdesktop-10.0;windowsdesktop-3.0;windowsdesktop-3.1;windowsdesktop-5.0;windowsdesktop-6.0;windowsdesktop-8.0;windowsdesktop-9.0">
<AttributeName Language="C#">[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)>]</AttributeName>
</Attribute>
<Attribute>
<AttributeName Language="C#">[System.Windows.Markup.DependsOn("VisualTree")]</AttributeName>
<AttributeName Language="F#">[<System.Windows.Markup.DependsOn("VisualTree")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;windowsdesktop-10.0;windowsdesktop-3.0;windowsdesktop-3.1;windowsdesktop-5.0;windowsdesktop-6.0;windowsdesktop-7.0;windowsdesktop-8.0;windowsdesktop-9.0">
<AttributeName Language="C#">[System.Windows.Markup.DependsOn("Template")]</AttributeName>
<AttributeName Language="F#">[<System.Windows.Markup.DependsOn("Template")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="windowsdesktop-7.0">
<AttributeName Language="C#">[System.ComponentModel.DesignerSerializationVisibility]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DesignerSerializationVisibility>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Windows.TriggerCollection</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a collection of <see cref="T:System.Windows.TriggerBase" /> objects that apply property changes or perform actions based on specified conditions.</summary>
<value>A collection of <see cref="T:System.Windows.TriggerBase" /> objects. The default value is <see langword="null" />.</value>
<remarks>
<format type="text/markdown"><.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="ValidateTemplatedParent">
<MemberSignature Language="C#" Value="protected override void ValidateTemplatedParent (System.Windows.FrameworkElement templatedParent);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig virtual instance void ValidateTemplatedParent(class System.Windows.FrameworkElement templatedParent) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Controls.ControlTemplate.ValidateTemplatedParent(System.Windows.FrameworkElement)" />
<MemberSignature Language="VB.NET" Value="Protected Overrides Sub ValidateTemplatedParent (templatedParent As FrameworkElement)" />
<MemberSignature Language="F#" Value="override this.ValidateTemplatedParent : System.Windows.FrameworkElement -> unit" Usage="controlTemplate.ValidateTemplatedParent templatedParent" />
<MemberSignature Language="C++ CLI" Value="protected:
 override void ValidateTemplatedParent(System::Windows::FrameworkElement ^ templatedParent);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="templatedParent" Type="System.Windows.FrameworkElement" />
</Parameters>
<Docs>
<param name="templatedParent">The element this template is applied to.</param>
<summary>Checks the templated parent against a set of rules.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The method uses the following rules:
1. The `templatedParent` cannot be of type <xref:System.Windows.FrameworkContentElement>.
2. The `templatedParent` cannot be of type <xref:System.Windows.FrameworkElement> that is not a <xref:System.Windows.Controls.Control>.
3. The `templatedParent` cannot be a <xref:System.Windows.Controls.Control> that is not associated with the <xref:System.Windows.Controls.ControlTemplate>.
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The <paramref name="templatedParent" /> must not be <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">You must associate the <see cref="T:System.Windows.Controls.ControlTemplate" /> with a <see cref="T:System.Windows.Controls.Control" /> by setting the <see cref="P:System.Windows.Controls.Control.Template" /> property before using the <see cref="T:System.Windows.Controls.ControlTemplate" /> on the <see cref="T:System.Windows.Controls.Control" />.</exception>
</Docs>
</Member>
</Members>
</Type>