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
- TextPattern.cs
- DataColumn.cs
- LogRestartAreaEnumerator.cs
- HelpInfo.cs
- DataGridClipboardCellContent.cs
- PrintingPermissionAttribute.cs
- _StreamFramer.cs
- XslTransform.cs
- HScrollBar.cs
- Empty.cs
- SubpageParaClient.cs
- MeasurementDCInfo.cs
- RightsManagementProvider.cs
- DataPagerCommandEventArgs.cs
- ping.cs
- ContentPresenter.cs
- AssemblyEvidenceFactory.cs
- CompoundFileIOPermission.cs
- WmfPlaceableFileHeader.cs
- SecurityDescriptor.cs
- RsaSecurityKey.cs
- NativeObjectSecurity.cs
- Vector.cs
- SurrogateSelector.cs
- ListControl.cs
- InvokeDelegate.cs
- AssemblyResourceLoader.cs
- XmlCDATASection.cs
- Helper.cs
- NegatedConstant.cs
- LocalizationParserHooks.cs
- ParameterCollection.cs
- GestureRecognizer.cs
- TabControlAutomationPeer.cs
- ObjectPersistData.cs
- regiisutil.cs
- HierarchicalDataBoundControl.cs
- GridViewUpdateEventArgs.cs
- UInt32.cs
- PerspectiveCamera.cs
- QueryInterceptorAttribute.cs
- SignedXml.cs
- DefaultHttpHandler.cs
- PathParser.cs
- LiteralControl.cs
- TypeTypeConverter.cs
- ParserExtension.cs
- ChameleonKey.cs
- ChannelSinkStacks.cs
- CollectionViewProxy.cs
- PropertyGroupDescription.cs
- TypeConverterHelper.cs
- XmlDocumentFragment.cs
- DiscoveryClientChannelBase.cs
- AxisAngleRotation3D.cs
- NotificationContext.cs
- DelegateBodyWriter.cs
- SerializerWriterEventHandlers.cs
- ObjectPersistData.cs
- XmlAnyElementAttribute.cs
- CssClassPropertyAttribute.cs
- ExecutionContext.cs
- COM2FontConverter.cs
- HtmlContainerControl.cs
- StartUpEventArgs.cs
- XmlILModule.cs
- TraceShell.cs
- OLEDB_Util.cs
- SQLDecimalStorage.cs
- WriteableBitmap.cs
- StateMachineTimers.cs
- AlternateView.cs
- RelationshipNavigation.cs
- StylusPointDescription.cs
- DispatcherEventArgs.cs
- CompiledQuery.cs
- SqlCacheDependency.cs
- GridItem.cs
- MethodCallConverter.cs
- MenuCommand.cs
- VirtualPathProvider.cs
- ScriptReference.cs
- OrderedDictionary.cs
- UnsafePeerToPeerMethods.cs
- TabControlCancelEvent.cs
- DesignerAutoFormatStyle.cs
- LongValidator.cs
- SoapIgnoreAttribute.cs
- Utility.cs
- WeakReferenceList.cs
- ExpandSegment.cs
- BoundConstants.cs
- AssociatedControlConverter.cs
- OleDbWrapper.cs
- FixedSOMPageElement.cs
- AssertHelper.cs
- MachineKeySection.cs
- _RequestCacheProtocol.cs
- PageThemeCodeDomTreeGenerator.cs
- RadioButtonRenderer.cs