Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / DynamicResourceExtension.cs / 1 / DynamicResourceExtension.cs
/****************************************************************************\
*
* File: DynamicResourceExtension.cs
*
* Class for Xaml markup extension for static resource references.
*
* Copyright (C) 2004 by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Markup;
using System.Reflection;
using MS.Internal; // Helper
namespace System.Windows
{
///
/// Class for Xaml markup extension for static resource references.
///
[TypeConverter(typeof(DynamicResourceExtensionConverter))]
[MarkupExtensionReturnType(typeof(object))]
public class DynamicResourceExtension : MarkupExtension
{
///
/// Constructor that takes no parameters
///
public DynamicResourceExtension()
{
}
///
/// Constructor that takes the resource key that this is a static reference to.
///
public DynamicResourceExtension(
object resourceKey)
{
if (resourceKey == null)
{
throw new ArgumentNullException("resourceKey");
}
_resourceKey = resourceKey;
}
///
/// Return an object that should be set on the targetObject's targetProperty
/// for this markup extension. For DynamicResourceExtension, this is the object found in
/// a resource dictionary in the current parent chain that is keyed by ResourceKey
///
///
/// The object to set on this property.
///
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (ResourceKey == null)
{
throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionResourceKey));
}
if (serviceProvider != null)
{
IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
// DynamicResourceExtensions are not allowed On CLR props except for Setter,Trigger,Condition (bugs 1183373,1572537)
DependencyObject targetDependencyObject;
DependencyProperty targetDependencyProperty;
Helper.CheckCanReceiveMarkupExtension(this, provideValueTarget, out targetDependencyObject, out targetDependencyProperty);
}
return new ResourceReferenceExpression(ResourceKey);
}
///
/// The key in a Resource Dictionary used to find the object refered to by this
/// Markup Extension.
///
[ConstructorArgument("resourceKey")] // Uses an instance descriptor
public object ResourceKey
{
get { return _resourceKey; }
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_resourceKey = value;
}
}
private object _resourceKey;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
/****************************************************************************\
*
* File: DynamicResourceExtension.cs
*
* Class for Xaml markup extension for static resource references.
*
* Copyright (C) 2004 by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Markup;
using System.Reflection;
using MS.Internal; // Helper
namespace System.Windows
{
///
/// Class for Xaml markup extension for static resource references.
///
[TypeConverter(typeof(DynamicResourceExtensionConverter))]
[MarkupExtensionReturnType(typeof(object))]
public class DynamicResourceExtension : MarkupExtension
{
///
/// Constructor that takes no parameters
///
public DynamicResourceExtension()
{
}
///
/// Constructor that takes the resource key that this is a static reference to.
///
public DynamicResourceExtension(
object resourceKey)
{
if (resourceKey == null)
{
throw new ArgumentNullException("resourceKey");
}
_resourceKey = resourceKey;
}
///
/// Return an object that should be set on the targetObject's targetProperty
/// for this markup extension. For DynamicResourceExtension, this is the object found in
/// a resource dictionary in the current parent chain that is keyed by ResourceKey
///
///
/// The object to set on this property.
///
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (ResourceKey == null)
{
throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionResourceKey));
}
if (serviceProvider != null)
{
IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
// DynamicResourceExtensions are not allowed On CLR props except for Setter,Trigger,Condition (bugs 1183373,1572537)
DependencyObject targetDependencyObject;
DependencyProperty targetDependencyProperty;
Helper.CheckCanReceiveMarkupExtension(this, provideValueTarget, out targetDependencyObject, out targetDependencyProperty);
}
return new ResourceReferenceExpression(ResourceKey);
}
///
/// The key in a Resource Dictionary used to find the object refered to by this
/// Markup Extension.
///
[ConstructorArgument("resourceKey")] // Uses an instance descriptor
public object ResourceKey
{
get { return _resourceKey; }
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_resourceKey = value;
}
}
private object _resourceKey;
}
}
// 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
- SmtpSpecifiedPickupDirectoryElement.cs
- BindingNavigatorDesigner.cs
- ActivityBuilderHelper.cs
- PropertyDescriptors.cs
- BindingList.cs
- ImageEditor.cs
- BaseTemplateCodeDomTreeGenerator.cs
- TextEditorSpelling.cs
- fixedPageContentExtractor.cs
- WMIInterop.cs
- SQLCharsStorage.cs
- CultureMapper.cs
- MaskedTextBoxTextEditor.cs
- TextDecoration.cs
- Part.cs
- ChameleonKey.cs
- TypeValidationEventArgs.cs
- PropertyEmitter.cs
- StorageTypeMapping.cs
- CheckBoxPopupAdapter.cs
- DbConnectionStringCommon.cs
- SelectorItemAutomationPeer.cs
- PageParserFilter.cs
- DictionaryContent.cs
- ExtensionDataObject.cs
- ReadWriteSpinLock.cs
- Keywords.cs
- EncoderFallback.cs
- XmlConvert.cs
- WindowsFormsHostAutomationPeer.cs
- NetCodeGroup.cs
- ProfileBuildProvider.cs
- CodeArrayCreateExpression.cs
- NativeMethods.cs
- XsltConvert.cs
- ViewManager.cs
- PeerApplicationLaunchInfo.cs
- ProcessModuleCollection.cs
- ArrayTypeMismatchException.cs
- XmlDomTextWriter.cs
- Pens.cs
- DataMisalignedException.cs
- HttpApplicationFactory.cs
- EdmConstants.cs
- UInt64Converter.cs
- BuildDependencySet.cs
- wgx_render.cs
- Int16Converter.cs
- TranslateTransform.cs
- SessionPageStatePersister.cs
- TypeConstant.cs
- XmlSiteMapProvider.cs
- DataGridViewCellParsingEventArgs.cs
- TableSectionStyle.cs
- Argument.cs
- SettingsContext.cs
- COM2PropertyDescriptor.cs
- Trustee.cs
- CryptoHandle.cs
- URLIdentityPermission.cs
- HighlightVisual.cs
- ListViewItem.cs
- VectorCollectionConverter.cs
- DockEditor.cs
- Pkcs9Attribute.cs
- brushes.cs
- ViewgenGatekeeper.cs
- IndentedWriter.cs
- AudioLevelUpdatedEventArgs.cs
- TrackBarRenderer.cs
- nulltextcontainer.cs
- AuthorizationRuleCollection.cs
- UrlPath.cs
- MetaForeignKeyColumn.cs
- DataRelationPropertyDescriptor.cs
- Normalization.cs
- SocketElement.cs
- SessionStateUtil.cs
- CompositeFontInfo.cs
- BuilderPropertyEntry.cs
- HwndSource.cs
- WebPartDesigner.cs
- ProgressChangedEventArgs.cs
- User.cs
- HttpValueCollection.cs
- GridViewColumnCollection.cs
- ListBox.cs
- DocumentStatusResources.cs
- TableLayoutCellPaintEventArgs.cs
- RemotingConfigParser.cs
- ApplicationTrust.cs
- UxThemeWrapper.cs
- FormatVersion.cs
- ValueQuery.cs
- EntityStoreSchemaFilterEntry.cs
- SchemaElementLookUpTableEnumerator.cs
- TrackingQueryElement.cs
- Transform.cs
- PrivilegeNotHeldException.cs
- SqlExpressionNullability.cs