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
- TypeContext.cs
- RelativeSource.cs
- MdiWindowListItemConverter.cs
- SeverityFilter.cs
- Point4D.cs
- PageContent.cs
- ServiceReference.cs
- FixUpCollection.cs
- ConsumerConnectionPointCollection.cs
- Cursors.cs
- DesignerDataView.cs
- SpanIndex.cs
- DirectionalLight.cs
- ZoomComboBox.cs
- DateTimeValueSerializerContext.cs
- prefixendpointaddressmessagefilter.cs
- RequestValidator.cs
- WebRequest.cs
- SQLBoolean.cs
- MemberRestriction.cs
- SystemIcmpV6Statistics.cs
- StoreContentChangedEventArgs.cs
- ValidatingPropertiesEventArgs.cs
- IteratorDescriptor.cs
- MenuCommand.cs
- Misc.cs
- CharacterMetrics.cs
- FormViewDeleteEventArgs.cs
- ArglessEventHandlerProxy.cs
- SqlFormatter.cs
- SafeMILHandleMemoryPressure.cs
- SqlCommand.cs
- SystemIcons.cs
- ThemeInfoAttribute.cs
- ValidationSummary.cs
- WmlValidationSummaryAdapter.cs
- UIElementPropertyUndoUnit.cs
- basecomparevalidator.cs
- MailBnfHelper.cs
- RelationshipDetailsCollection.cs
- SubclassTypeValidatorAttribute.cs
- AdPostCacheSubstitution.cs
- basemetadatamappingvisitor.cs
- ApplicationServiceManager.cs
- CheckoutException.cs
- SignatureToken.cs
- ResourceDictionary.cs
- CodeGeneratorOptions.cs
- CountAggregationOperator.cs
- SecurityResources.cs
- DisplayMemberTemplateSelector.cs
- FilteredReadOnlyMetadataCollection.cs
- WindowsRebar.cs
- AutomationIdentifier.cs
- DataGridViewCellStyleChangedEventArgs.cs
- ProfilePropertySettingsCollection.cs
- DependencyPropertyHelper.cs
- CrossContextChannel.cs
- BufferBuilder.cs
- DesignerTextWriter.cs
- WpfSharedXamlSchemaContext.cs
- Condition.cs
- DataGridColumn.cs
- UnsafeCollabNativeMethods.cs
- ValueTable.cs
- FormViewPagerRow.cs
- ViewManager.cs
- MessageBox.cs
- ConditionBrowserDialog.cs
- OperatingSystem.cs
- FixUp.cs
- PackageRelationship.cs
- BidOverLoads.cs
- CheckPair.cs
- Array.cs
- SmtpFailedRecipientException.cs
- ExtractorMetadata.cs
- InternalConfigSettingsFactory.cs
- BitmapDecoder.cs
- ChannelReliableSession.cs
- ReferentialConstraint.cs
- DataRelationCollection.cs
- ContextMarshalException.cs
- FtpCachePolicyElement.cs
- TableLayoutColumnStyleCollection.cs
- Model3DCollection.cs
- FlagsAttribute.cs
- SpecialNameAttribute.cs
- Color.cs
- AsyncSerializedWorker.cs
- ElementNotAvailableException.cs
- KeyTime.cs
- EventLogPermissionAttribute.cs
- SchemaNames.cs
- MatrixKeyFrameCollection.cs
- InstanceKeyCollisionException.cs
- TimeSpan.cs
- MaskedTextProvider.cs
- DelegateSerializationHolder.cs
- CodeCompileUnit.cs