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
- ItemContainerGenerator.cs
- QueryStringParameter.cs
- ToolboxDataAttribute.cs
- FreezableCollection.cs
- TranslateTransform.cs
- TableRow.cs
- HashSetEqualityComparer.cs
- ApplicationSettingsBase.cs
- __ComObject.cs
- ReflectionUtil.cs
- Win32KeyboardDevice.cs
- NativeMethods.cs
- SemanticResultKey.cs
- Helpers.cs
- DataGridHeaderBorder.cs
- basevalidator.cs
- HeaderedContentControl.cs
- TabPage.cs
- Reference.cs
- DbSource.cs
- SettingsBindableAttribute.cs
- ByteAnimation.cs
- GroupQuery.cs
- PropertyMap.cs
- DataGridViewImageCell.cs
- DbParameterHelper.cs
- StatusBarItem.cs
- DataGridRowHeader.cs
- NavigationExpr.cs
- FullTrustAssembly.cs
- RoleManagerEventArgs.cs
- CollectionContainer.cs
- CodeCatchClause.cs
- SqlFlattener.cs
- FocusTracker.cs
- ProgressBar.cs
- FormatException.cs
- NullableDecimalSumAggregationOperator.cs
- Equal.cs
- VisualProxy.cs
- BulletedList.cs
- XmlSchemaComplexContentRestriction.cs
- basecomparevalidator.cs
- DependencyObjectProvider.cs
- SingleAnimationUsingKeyFrames.cs
- CodeMemberField.cs
- TemplateManager.cs
- LoadWorkflowAsyncResult.cs
- GlyphRun.cs
- SymmetricKeyWrap.cs
- Page.cs
- WindowsComboBox.cs
- ElementFactory.cs
- SelectorItemAutomationPeer.cs
- SemanticResultValue.cs
- ComPersistableTypeElement.cs
- CustomErrorCollection.cs
- basenumberconverter.cs
- RelatedEnd.cs
- ServiceObjectContainer.cs
- TextAutomationPeer.cs
- CodeSnippetStatement.cs
- HttpListenerResponse.cs
- DataGridColumnDropSeparator.cs
- ListViewSelectEventArgs.cs
- XmlSchemaInclude.cs
- ServiceRouteHandler.cs
- EventMappingSettings.cs
- ArrayConverter.cs
- HTMLTextWriter.cs
- HttpApplication.cs
- MobileContainerDesigner.cs
- JsonServiceDocumentSerializer.cs
- TypedTableBase.cs
- DesignerExtenders.cs
- MenuItem.cs
- InlineObject.cs
- XmlnsPrefixAttribute.cs
- WindowsProgressbar.cs
- ServicePerformanceCounters.cs
- TCPListener.cs
- XmlElementAttribute.cs
- OperationResponse.cs
- IntegrationExceptionEventArgs.cs
- OdbcParameter.cs
- DataStreamFromComStream.cs
- HttpProfileBase.cs
- ListSourceHelper.cs
- MappingSource.cs
- XmlEnumAttribute.cs
- Keywords.cs
- TraceContextRecord.cs
- ToolBarButton.cs
- ConfigurationSectionGroup.cs
- GifBitmapDecoder.cs
- FixedPage.cs
- CharEnumerator.cs
- CopyOnWriteList.cs
- SqlAliaser.cs
- Control.cs