~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to class/Microsoft.SilverlightControls/Controls/Src/ContentControl/ContentControl.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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. 
 
5
 
 
6
using System;
 
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;
 
13
 
 
14
namespace System.Windows.Controls
 
15
{
 
16
    /// <summary>
 
17
    /// Represents a control with a single piece of content. 
 
18
    /// </summary> 
 
19
    /// <remarks>
 
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 &lt;ContentPresenter Content="{TemplateBinding Content}" /&gt;
 
23
    /// to display the value of the Content property. 
 
24
    /// </remarks>
 
25
    [ContentProperty("Content")]
 
26
    public partial class ContentControl : Control 
 
27
    { 
 
28
        #region Content
 
29
        /// <summary> 
 
30
        /// Gets or sets the content of a ContentControl.
 
31
        /// </summary>
 
32
        public object Content 
 
33
        {
 
34
            get { return GetValue(ContentProperty); }
 
35
            set { SetValue(ContentProperty, value); } 
 
36
        } 
 
37
 
 
38
        /// <summary> 
 
39
        /// Identifies the Content dependency property.
 
40
        /// </summary>
 
41
        public static readonly DependencyProperty ContentProperty = 
 
42
            DependencyProperty.Register(
 
43
                "Content",
 
44
                typeof(object), 
 
45
                typeof(ContentControl), 
 
46
                new PropertyMetadata(OnContentPropertyChanged));
 
47
 
 
48
        /// <summary>
 
49
        /// ContentProperty property changed handler.
 
50
        /// </summary> 
 
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) 
 
54
        { 
 
55
            ContentControl source = d as ContentControl;
 
56
            Debug.Assert(source != null, 
 
57
                "The source is not an instance of ContentControl!");
 
58
 
 
59
            // Notify derived classes of the change 
 
60
            source.OnContentChanged(e.OldValue, e.NewValue);
 
61
        }
 
62
        #endregion Content 
 
63
 
 
64
        #region ContentTemplate
 
65
        /// <summary> 
 
66
        /// Gets or sets the data template used to display the content of the
 
67
        /// ContentControl.
 
68
        /// </summary> 
 
69
        public DataTemplate ContentTemplate
 
70
        {
 
71
            get { return GetValue(ContentTemplateProperty) as DataTemplate; } 
 
72
            set { SetValue(ContentTemplateProperty, value); } 
 
73
        }
 
74
 
 
75
        /// <summary>
 
76
        /// Identifies the ContentTemplate dependency property.
 
77
        /// </summary> 
 
78
        public static readonly DependencyProperty ContentTemplateProperty =
 
79
            DependencyProperty.Register(
 
80
                "ContentTemplate", 
 
81
                typeof(DataTemplate), 
 
82
                typeof(ContentControl),
 
83
                new PropertyMetadata(OnContentTemplatePropertyChanged)); 
 
84
 
 
85
        /// <summary>
 
86
        /// ContentTemplateProperty property changed handler. 
 
87
        /// </summary>
 
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) 
 
91
        {
 
92
            ContentControl source = d as ContentControl; 
 
93
            Debug.Assert(source != null,
 
94
                "The source is not an instance of ContentControl!");
 
95
 
 
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; 
 
99
 
 
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;
 
103
 
 
104
            // Notify derived classes of the change 
 
105
            source.OnContentTemplateChanged(oldValue, value);
 
106
        }
 
107
        #endregion ContentTemplate 
 
108
 
 
109
        #region IsEnabled 
 
110
        /// <summary>
 
111
        /// Gets or sets a value that indicates whether this element is enabled 
 
112
        /// in the user interface (UI).
 
113
        /// </summary>
 
114
        public bool IsEnabled 
 
115
        {
 
116
            get { return (bool) GetValue(IsEnabledProperty); }
 
117
            set { SetValue(IsEnabledProperty, value); } 
 
118
        } 
 
119
 
 
120
        /// <summary> 
 
121
        /// Identifies the IsEnabled dependency property.
 
122
        /// </summary>
 
123
        public static readonly DependencyProperty IsEnabledProperty = 
 
124
            DependencyProperty.Register(
 
125
                "IsEnabled",
 
126
                typeof(bool), 
 
127
                typeof(ContentControl), 
 
128
                new PropertyMetadata(OnIsEnabledPropertyChanged));
 
129
 
 
130
        /// <summary>
 
131
        /// IsEnabledProperty property changed handler.
 
132
        /// </summary> 
 
133
        /// <param name="d">ContentControl that changed IsEnabled.</param>
 
134
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
 
135
        private static void OnIsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
 
136
        { 
 
137
            ContentControl source = d as ContentControl;
 
138
            Debug.Assert(source != null, 
 
139
                "The source is not an instance of ContentControl!");
 
140
 
 
141
            Debug.Assert(typeof(bool).IsInstanceOfType(e.NewValue), 
 
142
                "The value is not an instance of bool!");
 
143
            bool value = (bool) e.NewValue;
 
144
 
 
145
            source.OnIsEnabledChanged(value); 
 
146
        }
 
147
        #endregion IsEnabled 
 
148
 
 
149
        #region TextAlignment
 
150
        /// <summary> 
 
151
        /// Gets or sets a value that indicates the horizontal alignment of text
 
152
        /// content.
 
153
        /// </summary> 
 
154
        public TextAlignment TextAlignment 
 
155
        {
 
156
            get { return (TextAlignment) GetValue(TextAlignmentProperty); } 
 
157
            set { SetValue(TextAlignmentProperty, value); }
 
158
        }
 
159
 
 
160
        /// <summary>
 
161
        /// Identifies the TextAlignment dependency property.
 
162
        /// </summary> 
 
163
        public static readonly DependencyProperty TextAlignmentProperty = 
 
164
            DependencyProperty.Register(
 
165
                "TextAlignment", 
 
166
                typeof(TextAlignment),
 
167
                typeof(ContentControl),
 
168
                null); 
 
169
        #endregion TextAlignment
 
170
 
 
171
        #region TextDecorations 
 
172
        /// <summary> 
 
173
        /// Gets or sets a TextDecorationCollection that contains the effects to
 
174
        /// apply to the Content text. 
 
175
        /// </summary>
 
176
        [TypeConverter(typeof(TextDecorationCollectionConverter))]
 
177
        public TextDecorationCollection TextDecorations 
 
178
        {
 
179
            get { return GetValue(TextDecorationsProperty) as TextDecorationCollection; }
 
180
            set { SetValue(TextDecorationsProperty, value); } 
 
181
        } 
 
182
 
 
183
        /// <summary> 
 
184
        /// Identifies the TextDecorations dependency property.
 
185
        /// </summary>
 
186
        public static readonly DependencyProperty TextDecorationsProperty = 
 
187
            DependencyProperty.Register(
 
188
                "TextDecorations",
 
189
                typeof(TextDecorationCollection), 
 
190
                typeof(ContentControl), 
 
191
                null);
 
192
        #endregion TextDecorations 
 
193
 
 
194
        #region TextWrapping
 
195
        /// <summary> 
 
196
        /// Gets or sets a value that indicates how any Content text should be
 
197
        /// wrapped.
 
198
        /// </summary> 
 
199
        public TextWrapping TextWrapping 
 
200
        {
 
201
            get { return (TextWrapping) GetValue(TextWrappingProperty); } 
 
202
            set { SetValue(TextWrappingProperty, value); }
 
203
        }
 
204
 
 
205
        /// <summary>
 
206
        /// Identifies the TextWrapping dependency property.
 
207
        /// </summary> 
 
208
        public static readonly DependencyProperty TextWrappingProperty = 
 
209
            DependencyProperty.Register(
 
210
                "TextWrapping", 
 
211
                typeof(TextWrapping),
 
212
                typeof(ContentControl),
 
213
                null); 
 
214
        #endregion TextWrapping
 
215
 
 
216
 
 
217
        #region ToolTip 
 
218
        /// <summary> 
 
219
        /// Gets or sets the tool-tip object that is displayed for this element
 
220
        /// in the user interface (UI). 
 
221
        /// </summary>
 
222
        public object ToolTip
 
223
        { 
 
224
            get { return ToolTipService.GetToolTip(this); }
 
225
            set { ToolTipService.SetToolTip(this, value); }
 
226
        } 
 
227
 
 
228
        #endregion ToolTip
 
229
 
 
230
        /// <summary>
 
231
        /// Initializes a new instance of the ContentControl class.
 
232
        /// </summary> 
 
233
        public ContentControl()
 
234
        {
 
235
        } 
 
236
 
 
237
        /// <summary>
 
238
        /// Called when the Content property changes. 
 
239
        /// </summary>
 
240
        /// <param name="oldContent">
 
241
        /// The old value of the Content property. 
 
242
        /// </param>
 
243
        /// <param name="newContent">
 
244
        /// The new value of the Content property. 
 
245
        /// </param> 
 
246
        protected virtual void OnContentChanged(object oldContent, object newContent)
 
247
        { 
 
248
        }
 
249
 
 
250
        /// <summary> 
 
251
        /// Called when the ContentTemplate property changes.
 
252
        /// </summary>
 
253
        /// <param name="oldContentTemplate"> 
 
254
        /// The old value of the ContentTemplate property. 
 
255
        /// </param>
 
256
        /// <param name="newContentTemplate"> 
 
257
        /// The new value of the ContentTemplate property.
 
258
        /// </param>
 
259
        protected virtual void OnContentTemplateChanged(DataTemplate oldContentTemplate, DataTemplate newContentTemplate) 
 
260
        {
 
261
        }
 
262
 
 
263
        /// <summary> 
 
264
        /// Called when the IsEnabled property changes.
 
265
        /// </summary> 
 
266
        /// <param name="isEnabled">New value of the IsEnabled property.</param>
 
267
        protected virtual void OnIsEnabledChanged(bool isEnabled)
 
268
        { 
 
269
        }
 
270
    }
 
271