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
- StringKeyFrameCollection.cs
- DataObjectAttribute.cs
- OciHandle.cs
- BlurBitmapEffect.cs
- WithParamAction.cs
- updateconfighost.cs
- ErrorWrapper.cs
- SelectionProcessor.cs
- ElementAtQueryOperator.cs
- SimpleWorkerRequest.cs
- XmlDictionaryString.cs
- SpellerInterop.cs
- XmlDownloadManager.cs
- QilList.cs
- ActivationServices.cs
- Int32.cs
- SortedList.cs
- WindowsSlider.cs
- PathStreamGeometryContext.cs
- Profiler.cs
- DecimalAnimationUsingKeyFrames.cs
- Win32.cs
- DataGridPageChangedEventArgs.cs
- SettingsContext.cs
- DomNameTable.cs
- Int32RectConverter.cs
- ToolboxBitmapAttribute.cs
- CodePageEncoding.cs
- ErrorTolerantObjectWriter.cs
- UIPermission.cs
- FixedSOMGroup.cs
- WmlFormAdapter.cs
- VisualTreeUtils.cs
- TextElement.cs
- ListItem.cs
- BufferAllocator.cs
- TTSEvent.cs
- CommonObjectSecurity.cs
- NonSerializedAttribute.cs
- FrameworkElementFactoryMarkupObject.cs
- TraceContextEventArgs.cs
- SqlConnectionStringBuilder.cs
- WorkflowMarkupSerializationException.cs
- WinCategoryAttribute.cs
- DependencySource.cs
- EntityModelBuildProvider.cs
- UdpDiscoveryEndpointProvider.cs
- Int16Converter.cs
- WindowInteractionStateTracker.cs
- SystemMulticastIPAddressInformation.cs
- FloaterParagraph.cs
- CommandDevice.cs
- TextTreeUndoUnit.cs
- RichTextBoxContextMenu.cs
- GacUtil.cs
- SevenBitStream.cs
- MergablePropertyAttribute.cs
- ComponentDispatcherThread.cs
- DriveInfo.cs
- WorkItem.cs
- XmlSubtreeReader.cs
- HybridCollection.cs
- AppSettingsExpressionBuilder.cs
- CollectionBase.cs
- DataGridCellItemAutomationPeer.cs
- TypeDependencyAttribute.cs
- DateBoldEvent.cs
- ModuleBuilderData.cs
- EnumValAlphaComparer.cs
- DataGridViewAutoSizeModeEventArgs.cs
- ObjectReaderCompiler.cs
- SecurityDocument.cs
- PropertyEmitterBase.cs
- DataServiceCollectionOfT.cs
- UserControlFileEditor.cs
- RC2.cs
- GridViewEditEventArgs.cs
- WCFModelStrings.Designer.cs
- AppDomainFactory.cs
- ConversionContext.cs
- KernelTypeValidation.cs
- XpsFilter.cs
- StylusDevice.cs
- ProtocolsConfigurationHandler.cs
- MessageSecurityOverHttp.cs
- TimeEnumHelper.cs
- ThemeInfoAttribute.cs
- DocumentOutline.cs
- dbenumerator.cs
- PDBReader.cs
- TextElementEditingBehaviorAttribute.cs
- LoginUtil.cs
- NominalTypeEliminator.cs
- SpecialNameAttribute.cs
- ReaderWriterLock.cs
- ContainerUIElement3D.cs
- SQLByteStorage.cs
- Object.cs
- UInt16.cs
- DbConnectionFactory.cs