1
ļ»æ// Copyright Ā© Microsoft Corporation.
2
// This source is subject to the Microsoft Source License for Silverlight Controls (March 2008 Release).
3
// Please see http://go.microsoft.com/fwlink/?LinkID=111693 for details.
4
// All other rights reserved.
7
using System.ComponentModel;
8
using System.Diagnostics;
9
using System.Windows.Documents;
10
using System.Windows.Markup;
11
using System.Windows.Media;
12
using System.Windows.Controls;
14
namespace System.Windows.Controls
17
/// Represents a control with a single piece of content.
20
/// A ContentControl has a limited default style. If you want to enhance
21
/// the appearance of the control, you can create a new control template
22
/// that uses <ContentPresenter Content="{TemplateBinding Content}" />
23
/// to display the value of the Content property.
25
[ContentProperty("Content")]
26
public partial class ContentControl : Control
30
/// Gets or sets the content of a ContentControl.
34
get { return GetValue(ContentProperty); }
35
set { SetValue(ContentProperty, value); }
39
/// Identifies the Content dependency property.
41
public static readonly DependencyProperty ContentProperty =
42
DependencyProperty.Register(
45
typeof(ContentControl),
46
new PropertyMetadata(OnContentPropertyChanged));
49
/// ContentProperty property changed handler.
51
/// <param name="d">ContentControl that changed its Content.</param>
52
/// <param name="e">DependencyPropertyChangedEventArgs.</param>
53
private static void OnContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
55
ContentControl source = d as ContentControl;
56
Debug.Assert(source != null,
57
"The source is not an instance of ContentControl!");
59
// Notify derived classes of the change
60
source.OnContentChanged(e.OldValue, e.NewValue);
64
#region ContentTemplate
66
/// Gets or sets the data template used to display the content of the
69
public DataTemplate ContentTemplate
71
get { return GetValue(ContentTemplateProperty) as DataTemplate; }
72
set { SetValue(ContentTemplateProperty, value); }
76
/// Identifies the ContentTemplate dependency property.
78
public static readonly DependencyProperty ContentTemplateProperty =
79
DependencyProperty.Register(
82
typeof(ContentControl),
83
new PropertyMetadata(OnContentTemplatePropertyChanged));
86
/// ContentTemplateProperty property changed handler.
88
/// <param name="d">ContentControl that changed its ContentTemplate.</param>
89
/// <param name="e">DependencyPropertyChangedEventArgs.</param>
90
private static void OnContentTemplatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
92
ContentControl source = d as ContentControl;
93
Debug.Assert(source != null,
94
"The source is not an instance of ContentControl!");
96
Debug.Assert(typeof(DataTemplate).IsInstanceOfType(e.NewValue) || (e.NewValue == null),
97
"The value is not an instance of DataTemplate!");
98
DataTemplate value = (DataTemplate) e.NewValue;
100
Debug.Assert(typeof(DataTemplate).IsInstanceOfType(e.OldValue) || (e.OldValue == null),
101
"The old value is not an instance of DataTemplate!");
102
DataTemplate oldValue = (DataTemplate) e.OldValue;
104
// Notify derived classes of the change
105
source.OnContentTemplateChanged(oldValue, value);
107
#endregion ContentTemplate
111
/// Gets or sets a value that indicates whether this element is enabled
112
/// in the user interface (UI).
114
public bool IsEnabled
116
get { return (bool) GetValue(IsEnabledProperty); }
117
set { SetValue(IsEnabledProperty, value); }
121
/// Identifies the IsEnabled dependency property.
123
public static readonly DependencyProperty IsEnabledProperty =
124
DependencyProperty.Register(
127
typeof(ContentControl),
128
new PropertyMetadata(OnIsEnabledPropertyChanged));
131
/// IsEnabledProperty property changed handler.
133
/// <param name="d">ContentControl that changed IsEnabled.</param>
134
/// <param name="e">DependencyPropertyChangedEventArgs.</param>
135
private static void OnIsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
137
ContentControl source = d as ContentControl;
138
Debug.Assert(source != null,
139
"The source is not an instance of ContentControl!");
141
Debug.Assert(typeof(bool).IsInstanceOfType(e.NewValue),
142
"The value is not an instance of bool!");
143
bool value = (bool) e.NewValue;
145
source.OnIsEnabledChanged(value);
149
#region TextAlignment
151
/// Gets or sets a value that indicates the horizontal alignment of text
154
public TextAlignment TextAlignment
156
get { return (TextAlignment) GetValue(TextAlignmentProperty); }
157
set { SetValue(TextAlignmentProperty, value); }
161
/// Identifies the TextAlignment dependency property.
163
public static readonly DependencyProperty TextAlignmentProperty =
164
DependencyProperty.Register(
166
typeof(TextAlignment),
167
typeof(ContentControl),
169
#endregion TextAlignment
171
#region TextDecorations
173
/// Gets or sets a TextDecorationCollection that contains the effects to
174
/// apply to the Content text.
176
[TypeConverter(typeof(TextDecorationCollectionConverter))]
177
public TextDecorationCollection TextDecorations
179
get { return GetValue(TextDecorationsProperty) as TextDecorationCollection; }
180
set { SetValue(TextDecorationsProperty, value); }
184
/// Identifies the TextDecorations dependency property.
186
public static readonly DependencyProperty TextDecorationsProperty =
187
DependencyProperty.Register(
189
typeof(TextDecorationCollection),
190
typeof(ContentControl),
192
#endregion TextDecorations
196
/// Gets or sets a value that indicates how any Content text should be
199
public TextWrapping TextWrapping
201
get { return (TextWrapping) GetValue(TextWrappingProperty); }
202
set { SetValue(TextWrappingProperty, value); }
206
/// Identifies the TextWrapping dependency property.
208
public static readonly DependencyProperty TextWrappingProperty =
209
DependencyProperty.Register(
211
typeof(TextWrapping),
212
typeof(ContentControl),
214
#endregion TextWrapping
219
/// Gets or sets the tool-tip object that is displayed for this element
220
/// in the user interface (UI).
222
public object ToolTip
224
get { return ToolTipService.GetToolTip(this); }
225
set { ToolTipService.SetToolTip(this, value); }
231
/// Initializes a new instance of the ContentControl class.
233
public ContentControl()
238
/// Called when the Content property changes.
240
/// <param name="oldContent">
241
/// The old value of the Content property.
243
/// <param name="newContent">
244
/// The new value of the Content property.
246
protected virtual void OnContentChanged(object oldContent, object newContent)
251
/// Called when the ContentTemplate property changes.
253
/// <param name="oldContentTemplate">
254
/// The old value of the ContentTemplate property.
256
/// <param name="newContentTemplate">
257
/// The new value of the ContentTemplate property.
259
protected virtual void OnContentTemplateChanged(DataTemplate oldContentTemplate, DataTemplate newContentTemplate)
264
/// Called when the IsEnabled property changes.
266
/// <param name="isEnabled">New value of the IsEnabled property.</param>
267
protected virtual void OnIsEnabledChanged(bool isEnabled)