Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / DataTemplate.cs / 1 / DataTemplate.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description: DataTemplate describes how to display a single data item.
//
// Specs: http://avalon/coreui/Specs%20%20Property%20Engine/Styling%20Revisited.doc
//
//---------------------------------------------------------------------------
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Markup;
namespace System.Windows
{
///
/// DataTemplate describes how to display a single data item.
///
[DictionaryKeyProperty("DataTemplateKey")]
public class DataTemplate : FrameworkTemplate
{
#region Constructors
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
///
/// DataTemplate Constructor
///
public DataTemplate()
{
}
///
/// DataTemplate Constructor
///
public DataTemplate(object dataType)
{
Exception ex = TemplateKey.ValidateDataType(dataType, "dataType");
if (ex != null)
throw ex;
_dataType = dataType;
}
#endregion Constructors
#region Public Properties
//--------------------------------------------------------------------
//
// Public Properties
//
//-------------------------------------------------------------------
///
/// DataType for this DataTemplate. If the template is intended
/// for object data, this is the Type of the data. If the
/// template is intended for XML data, this is the tag name
/// of the data (i.e. a string).
///
[DefaultValue(null)]
public object DataType
{
get { return _dataType; }
set
{
Exception ex = TemplateKey.ValidateDataType(value, "value");
if (ex != null)
throw ex;
CheckSealed();
_dataType = value;
}
}
///
/// Collection of Triggers
///
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[DependsOn("VisualTree")]
public TriggerCollection Triggers
{
get
{
if (_triggers == null)
{
_triggers = new TriggerCollection();
// If the template has been sealed prior to this the newly
// created TriggerCollection also needs to be sealed
if (IsSealed)
{
_triggers.Seal();
}
}
return _triggers;
}
}
///
/// The key that will be used if the DataTemplate is added to a
/// ResourceDictionary in Xaml without a specified Key (x:Key).
///
public object DataTemplateKey
{
get
{
return (DataType != null) ? new DataTemplateKey(DataType) : null;
}
}
#endregion PublicProperties
#region Internal Properties
//--------------------------------------------------------------------
//
// Internal Properties
//
//--------------------------------------------------------------------
//
// TargetType for DataTemplate. This is override is
// so FrameworkTemplate can see this property.
//
internal override Type TargetTypeInternal
{
get { return DefaultTargetType; }
}
// Subclasses must provide a way for the parser to directly set the
// target type. For DataTemplate, this is not allowed.
internal override void SetTargetTypeInternal(Type targetType)
{
throw new InvalidOperationException(SR.Get(SRID.TemplateNotTargetType));
}
//
// DataType for DataTemplate. This is override is
// so FrameworkTemplate can see this property.
//
internal override object DataTypeInternal
{
get { return DataType; }
}
//
// Collection of Triggers for a DataTemplate. This is
// override is so FrameworkTemplate can see this property.
//
internal override TriggerCollection TriggersInternal
{
get { return Triggers; }
}
// Target type of DataTrigger is ContentPresenter
static internal Type DefaultTargetType
{
get { return typeof(ContentPresenter); }
}
#endregion Internal Properties
#region Protected Methods
//-------------------------------------------------------------------
//
// Protected Methods
//
//--------------------------------------------------------------------
///
/// Validate against the following rules
/// 1. Must have a non-null feTemplatedParent
/// 2. A DataTemplate must be applied to a ContentPresenter
///
protected override void ValidateTemplatedParent(FrameworkElement templatedParent)
{
// Must have a non-null feTemplatedParent
if (templatedParent == null)
{
throw new ArgumentNullException("templatedParent");
}
// A DataTemplate must be applied to a ContentPresenter
if (!(templatedParent is ContentPresenter))
{
throw new ArgumentException(SR.Get(SRID.TemplateTargetTypeMismatch, "ContentPresenter", templatedParent.GetType().Name));
}
}
#endregion Protected Methods
#region Data
private object _dataType;
private TriggerCollection _triggers;
#endregion Data
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description: DataTemplate describes how to display a single data item.
//
// Specs: http://avalon/coreui/Specs%20%20Property%20Engine/Styling%20Revisited.doc
//
//---------------------------------------------------------------------------
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Markup;
namespace System.Windows
{
///
/// DataTemplate describes how to display a single data item.
///
[DictionaryKeyProperty("DataTemplateKey")]
public class DataTemplate : FrameworkTemplate
{
#region Constructors
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
///
/// DataTemplate Constructor
///
public DataTemplate()
{
}
///
/// DataTemplate Constructor
///
public DataTemplate(object dataType)
{
Exception ex = TemplateKey.ValidateDataType(dataType, "dataType");
if (ex != null)
throw ex;
_dataType = dataType;
}
#endregion Constructors
#region Public Properties
//--------------------------------------------------------------------
//
// Public Properties
//
//-------------------------------------------------------------------
///
/// DataType for this DataTemplate. If the template is intended
/// for object data, this is the Type of the data. If the
/// template is intended for XML data, this is the tag name
/// of the data (i.e. a string).
///
[DefaultValue(null)]
public object DataType
{
get { return _dataType; }
set
{
Exception ex = TemplateKey.ValidateDataType(value, "value");
if (ex != null)
throw ex;
CheckSealed();
_dataType = value;
}
}
///
/// Collection of Triggers
///
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[DependsOn("VisualTree")]
public TriggerCollection Triggers
{
get
{
if (_triggers == null)
{
_triggers = new TriggerCollection();
// If the template has been sealed prior to this the newly
// created TriggerCollection also needs to be sealed
if (IsSealed)
{
_triggers.Seal();
}
}
return _triggers;
}
}
///
/// The key that will be used if the DataTemplate is added to a
/// ResourceDictionary in Xaml without a specified Key (x:Key).
///
public object DataTemplateKey
{
get
{
return (DataType != null) ? new DataTemplateKey(DataType) : null;
}
}
#endregion PublicProperties
#region Internal Properties
//--------------------------------------------------------------------
//
// Internal Properties
//
//--------------------------------------------------------------------
//
// TargetType for DataTemplate. This is override is
// so FrameworkTemplate can see this property.
//
internal override Type TargetTypeInternal
{
get { return DefaultTargetType; }
}
// Subclasses must provide a way for the parser to directly set the
// target type. For DataTemplate, this is not allowed.
internal override void SetTargetTypeInternal(Type targetType)
{
throw new InvalidOperationException(SR.Get(SRID.TemplateNotTargetType));
}
//
// DataType for DataTemplate. This is override is
// so FrameworkTemplate can see this property.
//
internal override object DataTypeInternal
{
get { return DataType; }
}
//
// Collection of Triggers for a DataTemplate. This is
// override is so FrameworkTemplate can see this property.
//
internal override TriggerCollection TriggersInternal
{
get { return Triggers; }
}
// Target type of DataTrigger is ContentPresenter
static internal Type DefaultTargetType
{
get { return typeof(ContentPresenter); }
}
#endregion Internal Properties
#region Protected Methods
//-------------------------------------------------------------------
//
// Protected Methods
//
//--------------------------------------------------------------------
///
/// Validate against the following rules
/// 1. Must have a non-null feTemplatedParent
/// 2. A DataTemplate must be applied to a ContentPresenter
///
protected override void ValidateTemplatedParent(FrameworkElement templatedParent)
{
// Must have a non-null feTemplatedParent
if (templatedParent == null)
{
throw new ArgumentNullException("templatedParent");
}
// A DataTemplate must be applied to a ContentPresenter
if (!(templatedParent is ContentPresenter))
{
throw new ArgumentException(SR.Get(SRID.TemplateTargetTypeMismatch, "ContentPresenter", templatedParent.GetType().Name));
}
}
#endregion Protected Methods
#region Data
private object _dataType;
private TriggerCollection _triggers;
#endregion Data
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListItemCollection.cs
- FilteredReadOnlyMetadataCollection.cs
- XmlSerializerNamespaces.cs
- SkewTransform.cs
- UdpTransportSettingsElement.cs
- EntityModelBuildProvider.cs
- StateFinalizationDesigner.cs
- BStrWrapper.cs
- VirtualDirectoryMapping.cs
- sqlser.cs
- HtmlHead.cs
- Knowncolors.cs
- AuthenticateEventArgs.cs
- SrgsRule.cs
- TypeSystem.cs
- Button.cs
- SlotInfo.cs
- PageFunction.cs
- UrlPath.cs
- EdmProviderManifest.cs
- MeshGeometry3D.cs
- dtdvalidator.cs
- FlowDocumentScrollViewer.cs
- BitmapDecoder.cs
- NavigationProperty.cs
- TextDecorationCollectionConverter.cs
- WebPartZoneCollection.cs
- ConsoleEntryPoint.cs
- XmlSerializerFactory.cs
- InProcStateClientManager.cs
- ProviderSettings.cs
- ActivitySurrogate.cs
- SecurityTokenSpecification.cs
- MemberExpression.cs
- SortedList.cs
- Utilities.cs
- ImageConverter.cs
- SqlDataSourceCache.cs
- CapabilitiesState.cs
- XmlWriterTraceListener.cs
- SecurityCriticalDataForSet.cs
- InternalConfigSettingsFactory.cs
- dataobject.cs
- RoleManagerEventArgs.cs
- Tile.cs
- StringValidatorAttribute.cs
- Speller.cs
- PathFigureCollection.cs
- XsdDataContractExporter.cs
- ConditionValidator.cs
- CloudCollection.cs
- MetadataFile.cs
- ControlBuilderAttribute.cs
- ICspAsymmetricAlgorithm.cs
- TextRangeEditLists.cs
- LinkedResource.cs
- ECDiffieHellmanPublicKey.cs
- PageCatalogPart.cs
- ProcessProtocolHandler.cs
- PublisherIdentityPermission.cs
- PeerNameResolver.cs
- CustomValidator.cs
- HtmlListAdapter.cs
- xmlsaver.cs
- TitleStyle.cs
- FixUpCollection.cs
- FilterableAttribute.cs
- BamlResourceContent.cs
- TextEditorThreadLocalStore.cs
- CompareValidator.cs
- AddInContractAttribute.cs
- ConsumerConnectionPointCollection.cs
- SqlDataReader.cs
- XmlQueryType.cs
- ExceptionUtil.cs
- FormsAuthenticationEventArgs.cs
- TrackBarRenderer.cs
- SkipStoryboardToFill.cs
- WindowsSpinner.cs
- EncodingTable.cs
- InputProviderSite.cs
- WebColorConverter.cs
- DocumentApplicationJournalEntry.cs
- Rotation3DAnimationUsingKeyFrames.cs
- ServiceRoute.cs
- CellPartitioner.cs
- LeaseManager.cs
- MultiViewDesigner.cs
- SQLString.cs
- HandledMouseEvent.cs
- SystemIPAddressInformation.cs
- TriggerAction.cs
- OptimisticConcurrencyException.cs
- RemotingSurrogateSelector.cs
- OleDbError.cs
- HtmlProps.cs
- Drawing.cs
- DataRecordInternal.cs
- QuaternionValueSerializer.cs
- KeyedHashAlgorithm.cs