Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / ItemsPanelTemplate.cs / 1305600 / ItemsPanelTemplate.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: ItemsPanelTemplate describes how ItemsPresenter creates the panel // that manages layout of containers for an ItemsControl. // // Specs: // //--------------------------------------------------------------------------- using System.ComponentModel; using System.Windows.Controls; using System.Windows.Markup; using System.Diagnostics; namespace System.Windows.Controls { ////// ItemsPanelTemplate describes how ItemsPresenter creates the panel /// that manages layout of containers for an ItemsControl. /// public class ItemsPanelTemplate : FrameworkTemplate { #region Constructors //------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------- ////// ItemsPanelTemplate Constructor /// public ItemsPanelTemplate() { } ////// ItemsPanelTemplate Constructor /// public ItemsPanelTemplate(FrameworkElementFactory root) { VisualTree = root; } #endregion Constructors #region Public Properties //-------------------------------------------------------------------- // // Public Properties // //------------------------------------------------------------------- #endregion PublicProperties #region Internal Properties //-------------------------------------------------------------------- // // Internal Properties // //-------------------------------------------------------------------- // // TargetType for ItemsPanelTemplate. 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 ItemsPanelTemplate, this is not allowed. internal override void SetTargetTypeInternal(Type targetType) { throw new InvalidOperationException(SR.Get(SRID.TemplateNotTargetType)); } // Target type of ItemsPanelTemplate is ItemsPresenter static internal Type DefaultTargetType { get { return typeof(ItemsPresenter); } } #endregion Internal Properties #region Internal Methods //------------------------------------------------------------------- // // Internal Methods // //-------------------------------------------------------------------- // // ProcessTemplateBeforeSeal // // This is used in the case of templates defined with FEFs. For templates // in Baml (the typical case), see the OnApply override. // // 1. Verify that // a. root element is a Panel // 2. Set IsItemsHost = true // internal override void ProcessTemplateBeforeSeal() { FrameworkElementFactory root; if( HasContent ) { // This is a Baml-style template // Validate the root type (it must be a Panel) TemplateContent templateHolder = Template as TemplateContent; System.Xaml.XamlType panelType = templateHolder.SchemaContext.GetXamlType(typeof(Panel)); if (templateHolder.RootType == null || !templateHolder.RootType.CanAssignTo(panelType)) { throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, templateHolder.RootType)); } } else if ((root = this.VisualTree) != null) { // This is a FEF-style template if (!typeof(Panel).IsAssignableFrom(root.Type)) throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, root.Type)); root.SetValue(Panel.IsItemsHostProperty, true); } } #endregion Internal Methods #region Protected Methods //------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------- ////// Validate against the following rules /// 1. Must have a non-null feTemplatedParent /// 2. A ItemsPanelTemplate 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 ItemsPanelTemplate must be applied to an ItemsPresenter if (!(templatedParent is ItemsPresenter)) { throw new ArgumentException(SR.Get(SRID.TemplateTargetTypeMismatch, "ItemsPresenter", templatedParent.GetType().Name)); } } #endregion Protected Methods } } // 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: ItemsPanelTemplate describes how ItemsPresenter creates the panel // that manages layout of containers for an ItemsControl. // // Specs: // //--------------------------------------------------------------------------- using System.ComponentModel; using System.Windows.Controls; using System.Windows.Markup; using System.Diagnostics; namespace System.Windows.Controls { ////// ItemsPanelTemplate describes how ItemsPresenter creates the panel /// that manages layout of containers for an ItemsControl. /// public class ItemsPanelTemplate : FrameworkTemplate { #region Constructors //------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------- ////// ItemsPanelTemplate Constructor /// public ItemsPanelTemplate() { } ////// ItemsPanelTemplate Constructor /// public ItemsPanelTemplate(FrameworkElementFactory root) { VisualTree = root; } #endregion Constructors #region Public Properties //-------------------------------------------------------------------- // // Public Properties // //------------------------------------------------------------------- #endregion PublicProperties #region Internal Properties //-------------------------------------------------------------------- // // Internal Properties // //-------------------------------------------------------------------- // // TargetType for ItemsPanelTemplate. 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 ItemsPanelTemplate, this is not allowed. internal override void SetTargetTypeInternal(Type targetType) { throw new InvalidOperationException(SR.Get(SRID.TemplateNotTargetType)); } // Target type of ItemsPanelTemplate is ItemsPresenter static internal Type DefaultTargetType { get { return typeof(ItemsPresenter); } } #endregion Internal Properties #region Internal Methods //------------------------------------------------------------------- // // Internal Methods // //-------------------------------------------------------------------- // // ProcessTemplateBeforeSeal // // This is used in the case of templates defined with FEFs. For templates // in Baml (the typical case), see the OnApply override. // // 1. Verify that // a. root element is a Panel // 2. Set IsItemsHost = true // internal override void ProcessTemplateBeforeSeal() { FrameworkElementFactory root; if( HasContent ) { // This is a Baml-style template // Validate the root type (it must be a Panel) TemplateContent templateHolder = Template as TemplateContent; System.Xaml.XamlType panelType = templateHolder.SchemaContext.GetXamlType(typeof(Panel)); if (templateHolder.RootType == null || !templateHolder.RootType.CanAssignTo(panelType)) { throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, templateHolder.RootType)); } } else if ((root = this.VisualTree) != null) { // This is a FEF-style template if (!typeof(Panel).IsAssignableFrom(root.Type)) throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, root.Type)); root.SetValue(Panel.IsItemsHostProperty, true); } } #endregion Internal Methods #region Protected Methods //------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------- ////// Validate against the following rules /// 1. Must have a non-null feTemplatedParent /// 2. A ItemsPanelTemplate 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 ItemsPanelTemplate must be applied to an ItemsPresenter if (!(templatedParent is ItemsPresenter)) { throw new ArgumentException(SR.Get(SRID.TemplateTargetTypeMismatch, "ItemsPresenter", templatedParent.GetType().Name)); } } #endregion Protected Methods } } // 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
- CorrelationQueryBehavior.cs
- CellPartitioner.cs
- WSAddressing10ProblemHeaderQNameFault.cs
- MonitorWrapper.cs
- ProfileBuildProvider.cs
- EntitySetBaseCollection.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- SecurityChannel.cs
- ComPlusServiceHost.cs
- SelectionRangeConverter.cs
- MailWriter.cs
- WebPartAuthorizationEventArgs.cs
- AudienceUriMode.cs
- EventsTab.cs
- MultiPropertyDescriptorGridEntry.cs
- TimelineCollection.cs
- MaskDescriptors.cs
- SchemaNotation.cs
- WebScriptMetadataMessageEncoderFactory.cs
- TemplateParser.cs
- KeyValueConfigurationCollection.cs
- Invariant.cs
- Ipv6Element.cs
- MergePropertyDescriptor.cs
- PassportIdentity.cs
- TabItem.cs
- DataServiceProcessingPipelineEventArgs.cs
- XPathScanner.cs
- SmiEventSink_DeferedProcessing.cs
- SamlSubject.cs
- TypefaceMetricsCache.cs
- LogLogRecord.cs
- TextTreeExtractElementUndoUnit.cs
- webeventbuffer.cs
- TextTrailingCharacterEllipsis.cs
- PostBackOptions.cs
- Avt.cs
- HttpConfigurationSystem.cs
- CertificateElement.cs
- PageParser.cs
- EntitySetBaseCollection.cs
- LocalizationCodeDomSerializer.cs
- ReadOnlyState.cs
- wgx_exports.cs
- NavigationPropertyEmitter.cs
- PrimaryKeyTypeConverter.cs
- TextBlockAutomationPeer.cs
- ConnectionOrientedTransportElement.cs
- Help.cs
- MenuAdapter.cs
- ApplicationDirectoryMembershipCondition.cs
- TrailingSpaceComparer.cs
- DesignerDataStoredProcedure.cs
- MoveSizeWinEventHandler.cs
- NameValuePair.cs
- Connection.cs
- SafeWaitHandle.cs
- DataGridViewRowCancelEventArgs.cs
- CheckBoxField.cs
- JoinSymbol.cs
- TdsParserStaticMethods.cs
- ScriptComponentDescriptor.cs
- HttpInputStream.cs
- BigInt.cs
- DetailsViewAutoFormat.cs
- BooleanStorage.cs
- QuaternionAnimation.cs
- GridViewColumnCollection.cs
- NTAccount.cs
- CacheOutputQuery.cs
- CodeAccessPermission.cs
- OpenFileDialog.cs
- PanelStyle.cs
- OpenTypeCommon.cs
- FontFaceLayoutInfo.cs
- Rotation3DAnimationUsingKeyFrames.cs
- XmlILAnnotation.cs
- SqlSupersetValidator.cs
- SqlEnums.cs
- SecurityRuntime.cs
- KerberosReceiverSecurityToken.cs
- DbParameterCollection.cs
- ManifestResourceInfo.cs
- SoapMessage.cs
- BrowserCapabilitiesCompiler.cs
- X509ClientCertificateCredentialsElement.cs
- Parser.cs
- C14NUtil.cs
- WinEventHandler.cs
- StrokeSerializer.cs
- LayoutSettings.cs
- SmiTypedGetterSetter.cs
- DataBoundLiteralControl.cs
- SafeNativeMethodsCLR.cs
- JapaneseLunisolarCalendar.cs
- DecimalConverter.cs
- ParseChildrenAsPropertiesAttribute.cs
- DnsPermission.cs
- DesignerRegionCollection.cs
- AutomationPropertyChangedEventArgs.cs