Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TemplateModeChangedEventArgs.cs
- MergeLocalizationDirectives.cs
- SystemNetHelpers.cs
- WinCategoryAttribute.cs
- EnumValAlphaComparer.cs
- DocumentViewer.cs
- StrokeNodeData.cs
- UrlPath.cs
- ButtonBaseAdapter.cs
- FreezableOperations.cs
- listitem.cs
- ImpersonationContext.cs
- SecurityRuntime.cs
- MDIControlStrip.cs
- ClientSettingsStore.cs
- _FixedSizeReader.cs
- DesignerTransactionCloseEvent.cs
- PolicyImporterElementCollection.cs
- QueryCursorEventArgs.cs
- ConfigXmlDocument.cs
- NamespaceDisplay.xaml.cs
- DataGridColumnHeaderCollection.cs
- XmlReaderDelegator.cs
- HttpHandlerActionCollection.cs
- RepeatInfo.cs
- TextTreeInsertElementUndoUnit.cs
- EncoderBestFitFallback.cs
- SerializationInfoEnumerator.cs
- PersonalizationProviderHelper.cs
- _LazyAsyncResult.cs
- DeclarativeCatalogPart.cs
- SocketException.cs
- ListViewItemCollectionEditor.cs
- Polygon.cs
- EnlistmentTraceIdentifier.cs
- PasswordDeriveBytes.cs
- RenderContext.cs
- AssemblyFilter.cs
- ChannelSinkStacks.cs
- Brushes.cs
- ByteKeyFrameCollection.cs
- UITypeEditor.cs
- PasswordBoxAutomationPeer.cs
- _LazyAsyncResult.cs
- SettingsSavedEventArgs.cs
- ShaperBuffers.cs
- UnaryNode.cs
- LogSwitch.cs
- RichTextBox.cs
- StreamResourceInfo.cs
- ResetableIterator.cs
- SplineKeyFrames.cs
- Animatable.cs
- XmlSchemaAnnotation.cs
- TreePrinter.cs
- TypedRowHandler.cs
- EnlistmentState.cs
- ReadOnlyMetadataCollection.cs
- SingleAnimationBase.cs
- Point4DValueSerializer.cs
- HotCommands.cs
- XmlSchemaInferenceException.cs
- CodeSnippetExpression.cs
- SeverityFilter.cs
- TextEditorContextMenu.cs
- DataTemplate.cs
- ClientBuildManagerCallback.cs
- SystemFonts.cs
- HttpListener.cs
- RequestUriProcessor.cs
- ConnectorSelectionGlyph.cs
- EpmCustomContentDeSerializer.cs
- graph.cs
- SQLInt16.cs
- HeaderedItemsControl.cs
- SubMenuStyle.cs
- PaintValueEventArgs.cs
- iisPickupDirectory.cs
- DataGridViewControlCollection.cs
- FeatureSupport.cs
- _ConnectOverlappedAsyncResult.cs
- mansign.cs
- GZipStream.cs
- PrivilegedConfigurationManager.cs
- SolidColorBrush.cs
- FontSourceCollection.cs
- CommonObjectSecurity.cs
- AccessKeyManager.cs
- WebRequestModuleElement.cs
- ContactManager.cs
- UITypeEditor.cs
- TaskExtensions.cs
- XmlCDATASection.cs
- StickyNoteAnnotations.cs
- PrintPreviewControl.cs
- PathData.cs
- WebPartDescription.cs
- DbDataRecord.cs
- HttpConfigurationContext.cs
- TraceContext.cs