Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / MS / Internal / Data / DisplayMemberTemplateSelector.cs / 1 / DisplayMemberTemplateSelector.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: Defines DisplayMemberTemplateSelector class. // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using MS.Internal; namespace MS.Internal.Data { // Selects template appropriate for CLR/XML item in order to // display string property at DisplayMemberPath on the item. internal sealed class DisplayMemberTemplateSelector : DataTemplateSelector { ////// Constructor /// /// path to the member to display public DisplayMemberTemplateSelector(string displayMemberPath, string stringFormat) { Debug.Assert(!(String.IsNullOrEmpty(displayMemberPath) && String.IsNullOrEmpty(stringFormat))); _displayMemberPath = displayMemberPath; _stringFormat = stringFormat; } ////// Override this method to return an app specific /// The data content /// The container in which the content is to be displayed ///. /// a app specific template to apply. public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (XmlHelper.IsXmlNode(item)) { if (_xmlNodeContentTemplate == null) { _xmlNodeContentTemplate = new DataTemplate(); FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory(); Binding binding = new Binding(); binding.XPath = _displayMemberPath; binding.StringFormat = _stringFormat; text.SetBinding(TextBlock.TextProperty, binding); _xmlNodeContentTemplate.VisualTree = text; _xmlNodeContentTemplate.Seal(); } return _xmlNodeContentTemplate; } else { if (_clrNodeContentTemplate == null) { _clrNodeContentTemplate = new DataTemplate(); FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory(); Binding binding = new Binding(); binding.Path = new PropertyPath(_displayMemberPath); binding.StringFormat = _stringFormat; text.SetBinding(TextBlock.TextProperty, binding); _clrNodeContentTemplate.VisualTree = text; _clrNodeContentTemplate.Seal(); } return _clrNodeContentTemplate; } } private string _displayMemberPath; private string _stringFormat; private DataTemplate _xmlNodeContentTemplate; private DataTemplate _clrNodeContentTemplate; } } // 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: Defines DisplayMemberTemplateSelector class. // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using MS.Internal; namespace MS.Internal.Data { // Selects template appropriate for CLR/XML item in order to // display string property at DisplayMemberPath on the item. internal sealed class DisplayMemberTemplateSelector : DataTemplateSelector { ////// Constructor /// /// path to the member to display public DisplayMemberTemplateSelector(string displayMemberPath, string stringFormat) { Debug.Assert(!(String.IsNullOrEmpty(displayMemberPath) && String.IsNullOrEmpty(stringFormat))); _displayMemberPath = displayMemberPath; _stringFormat = stringFormat; } ////// Override this method to return an app specific /// The data content /// The container in which the content is to be displayed ///. /// a app specific template to apply. public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (XmlHelper.IsXmlNode(item)) { if (_xmlNodeContentTemplate == null) { _xmlNodeContentTemplate = new DataTemplate(); FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory(); Binding binding = new Binding(); binding.XPath = _displayMemberPath; binding.StringFormat = _stringFormat; text.SetBinding(TextBlock.TextProperty, binding); _xmlNodeContentTemplate.VisualTree = text; _xmlNodeContentTemplate.Seal(); } return _xmlNodeContentTemplate; } else { if (_clrNodeContentTemplate == null) { _clrNodeContentTemplate = new DataTemplate(); FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory(); Binding binding = new Binding(); binding.Path = new PropertyPath(_displayMemberPath); binding.StringFormat = _stringFormat; text.SetBinding(TextBlock.TextProperty, binding); _clrNodeContentTemplate.VisualTree = text; _clrNodeContentTemplate.Seal(); } return _clrNodeContentTemplate; } } private string _displayMemberPath; private string _stringFormat; private DataTemplate _xmlNodeContentTemplate; private DataTemplate _clrNodeContentTemplate; } } // 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
- XmlSerializerAssemblyAttribute.cs
- DataMemberAttribute.cs
- ReflectTypeDescriptionProvider.cs
- FormatException.cs
- QilLoop.cs
- ServerProtocol.cs
- CryptoHandle.cs
- OleDbPropertySetGuid.cs
- MessageQueueEnumerator.cs
- TaskExtensions.cs
- PropertyManager.cs
- MenuItemBinding.cs
- FillRuleValidation.cs
- isolationinterop.cs
- ManagementBaseObject.cs
- SspiNegotiationTokenProviderState.cs
- AbandonedMutexException.cs
- IdnMapping.cs
- SqlRowUpdatingEvent.cs
- TimeStampChecker.cs
- NameHandler.cs
- DoubleSumAggregationOperator.cs
- CodeAttributeDeclarationCollection.cs
- PersonalizationStateQuery.cs
- ImageSourceConverter.cs
- QuotedPrintableStream.cs
- SystemIcmpV6Statistics.cs
- Timeline.cs
- KeyFrames.cs
- SpecularMaterial.cs
- Model3DGroup.cs
- ServiceSettingsResponseInfo.cs
- SizeAnimationBase.cs
- DBConnectionString.cs
- WebPartCatalogAddVerb.cs
- OleDbPermission.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- Odbc32.cs
- QueryAccessibilityHelpEvent.cs
- ListViewGroup.cs
- RightsManagementEncryptedStream.cs
- SystemTcpStatistics.cs
- DocumentViewerConstants.cs
- ToolStripRenderer.cs
- TypedElement.cs
- ToggleButton.cs
- tibetanshape.cs
- ToolCreatedEventArgs.cs
- LineBreak.cs
- connectionpool.cs
- PtsHelper.cs
- ConnectionPoint.cs
- SourceFilter.cs
- WorkflowQueueInfo.cs
- ControlBuilder.cs
- TextMarkerSource.cs
- TextProviderWrapper.cs
- Encoding.cs
- StringDictionary.cs
- NamedPipeTransportSecurityElement.cs
- WebPartEditorApplyVerb.cs
- DataGridPageChangedEventArgs.cs
- AnnotationStore.cs
- ImageResources.Designer.cs
- XmlLanguage.cs
- CodeNamespaceImport.cs
- KeyToListMap.cs
- ObjectListCommand.cs
- CommandDevice.cs
- XmlObjectSerializerReadContext.cs
- BitArray.cs
- Track.cs
- AlternateView.cs
- SqlFunctions.cs
- DesignerAttribute.cs
- HTTPNotFoundHandler.cs
- _SslStream.cs
- CopyOfAction.cs
- LambdaReference.cs
- DisableDpiAwarenessAttribute.cs
- StrongName.cs
- FileUtil.cs
- _Events.cs
- StorageModelBuildProvider.cs
- ObjectDataSourceDisposingEventArgs.cs
- SafeHandles.cs
- NameObjectCollectionBase.cs
- HttpWebRequest.cs
- FragmentQueryKB.cs
- MemberListBinding.cs
- TreeNodeClickEventArgs.cs
- TextBoxBase.cs
- TypeConverter.cs
- SmiEventStream.cs
- XmlAttributeCache.cs
- LinkedResource.cs
- FlowLayout.cs
- InheritanceContextHelper.cs
- DropShadowBitmapEffect.cs
- XmlUtil.cs