Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- Symbol.cs
- AuthenticationModulesSection.cs
- SafeLibraryHandle.cs
- FrameworkElement.cs
- InheritedPropertyChangedEventArgs.cs
- CompilationSection.cs
- TitleStyle.cs
- XmlSerializerSection.cs
- PatternMatcher.cs
- GetRecipientListRequest.cs
- XmlImplementation.cs
- PingReply.cs
- StylusLogic.cs
- ForceCopyBuildProvider.cs
- BinHexEncoding.cs
- ObjectDataSourceSelectingEventArgs.cs
- HitTestDrawingContextWalker.cs
- ResourceAssociationTypeEnd.cs
- ThreadPool.cs
- ListItemParagraph.cs
- TabControl.cs
- EdmComplexTypeAttribute.cs
- Brush.cs
- WebPartVerbCollection.cs
- RelationalExpressions.cs
- JavaScriptObjectDeserializer.cs
- ADRoleFactory.cs
- BinarySerializer.cs
- CreateUserWizardStep.cs
- ScriptManager.cs
- PaintValueEventArgs.cs
- ServiceDescriptionReflector.cs
- TextCompositionEventArgs.cs
- DataRowChangeEvent.cs
- TypeUsageBuilder.cs
- StrongTypingException.cs
- __TransparentProxy.cs
- DataGridViewImageColumn.cs
- SaveFileDialog.cs
- Pair.cs
- Behavior.cs
- DataGridBoolColumn.cs
- RuleElement.cs
- OdbcHandle.cs
- StringConverter.cs
- LinkAreaEditor.cs
- ComponentRenameEvent.cs
- ToolTip.cs
- DrawItemEvent.cs
- MethodBuilderInstantiation.cs
- ToolStripDropTargetManager.cs
- SmtpAuthenticationManager.cs
- EngineSiteSapi.cs
- DbConnectionFactory.cs
- NativeMethods.cs
- TraceUtility.cs
- _emptywebproxy.cs
- QueryableDataSourceView.cs
- NativeMethods.cs
- TextFormatterImp.cs
- TopClause.cs
- SocketElement.cs
- FileChangeNotifier.cs
- basenumberconverter.cs
- ListView.cs
- peernodestatemanager.cs
- ApplicationSecurityManager.cs
- ColorBlend.cs
- FollowerQueueCreator.cs
- ResumeStoryboard.cs
- ConfigUtil.cs
- DesignerActionUIStateChangeEventArgs.cs
- WebBrowserProgressChangedEventHandler.cs
- SoapEnumAttribute.cs
- DmlSqlGenerator.cs
- Composition.cs
- SqlClientPermission.cs
- Image.cs
- SpellerInterop.cs
- EnumerableCollectionView.cs
- ContextMenuService.cs
- RangeBaseAutomationPeer.cs
- WebPartZone.cs
- DataGridViewAdvancedBorderStyle.cs
- HMACSHA384.cs
- AvtEvent.cs
- TextAutomationPeer.cs
- DecimalAverageAggregationOperator.cs
- MatrixTransform3D.cs
- ExpressionReplacer.cs
- DataGridViewCellValidatingEventArgs.cs
- XmlNamespaceMappingCollection.cs
- MexTcpBindingCollectionElement.cs
- MsmqChannelListenerBase.cs
- IDictionary.cs
- Thickness.cs
- PersonalizationStateQuery.cs
- Cursors.cs
- Events.cs
- Lease.cs