Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Data / DisplayMemberTemplateSelector.cs / 1305600 / 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 (AssemblyHelper.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 (AssemblyHelper.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
- IdentityModelStringsVersion1.cs
- ElasticEase.cs
- BrowserCapabilitiesCompiler.cs
- AnnotationResource.cs
- TableParaClient.cs
- RemotingAttributes.cs
- DirectoryRedirect.cs
- _SslStream.cs
- ObjectAnimationBase.cs
- SRGSCompiler.cs
- EntityException.cs
- Binding.cs
- RegexCharClass.cs
- TypeForwardedFromAttribute.cs
- Int64Animation.cs
- BmpBitmapDecoder.cs
- DocumentPage.cs
- SystemKeyConverter.cs
- AssociationSet.cs
- InputQueue.cs
- BamlResourceSerializer.cs
- WCFBuildProvider.cs
- ByteRangeDownloader.cs
- DataSourceGroupCollection.cs
- FormsAuthenticationEventArgs.cs
- NamespaceTable.cs
- ApplyTemplatesAction.cs
- TextPattern.cs
- ResourcesGenerator.cs
- SystemMulticastIPAddressInformation.cs
- StagingAreaInputItem.cs
- GetWorkflowTree.cs
- UpnEndpointIdentity.cs
- Model3DGroup.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- GPPOINT.cs
- RepeatButton.cs
- ThemeInfoAttribute.cs
- WebPartTransformer.cs
- SecurityException.cs
- XpsFilter.cs
- FileDialog.cs
- EmulateRecognizeCompletedEventArgs.cs
- ViewPort3D.cs
- ServiceModelStringsVersion1.cs
- ResXResourceWriter.cs
- SymDocumentType.cs
- PropertyPushdownHelper.cs
- ContextItemManager.cs
- TreeNode.cs
- HttpWebRequest.cs
- HotSpot.cs
- ServiceModelConfigurationSection.cs
- ChannelTerminatedException.cs
- ServiceChannelProxy.cs
- TextMetrics.cs
- JsonSerializer.cs
- TranslateTransform.cs
- HtmlEncodedRawTextWriter.cs
- SchemaContext.cs
- CalendarAutoFormatDialog.cs
- Point4D.cs
- DataColumnChangeEvent.cs
- WorkflowMarkupElementEventArgs.cs
- WSHttpBinding.cs
- TypeSystem.cs
- CompilationRelaxations.cs
- TableLayout.cs
- ByeMessage11.cs
- StatusStrip.cs
- NamespaceExpr.cs
- InterleavedZipPartStream.cs
- XmlProcessingInstruction.cs
- PrintEvent.cs
- DeferredSelectedIndexReference.cs
- CoTaskMemHandle.cs
- WebConvert.cs
- CacheForPrimitiveTypes.cs
- View.cs
- KeyValuePairs.cs
- XmlSortKey.cs
- Padding.cs
- KnownBoxes.cs
- TdsParserSafeHandles.cs
- BitSet.cs
- SByte.cs
- Vector3DCollectionValueSerializer.cs
- OneWayBindingElement.cs
- TransformProviderWrapper.cs
- RelatedImageListAttribute.cs
- ApplicationException.cs
- BinHexEncoding.cs
- Span.cs
- CompilerScopeManager.cs
- Size3DConverter.cs
- SecurityToken.cs
- SQlBooleanStorage.cs
- SqlGenericUtil.cs
- WebSysDescriptionAttribute.cs
- IISUnsafeMethods.cs