Share via


AdornerResources Class

Used to define a set of resources that can be used in XAML.

Inheritance Hierarchy

System.Object
  Microsoft.Windows.Design.Interaction.AdornerResources

Namespace:  Microsoft.Windows.Design.Interaction
Assembly:  Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)

Syntax

'Declaration
Public NotInheritable Class AdornerResources
public static class AdornerResources
public ref class AdornerResources abstract sealed
[<AbstractClass>]
[<Sealed>]
type AdornerResources =  class end
public final class AdornerResources

The AdornerResources type exposes the following members.

Methods

  Name Description
Public methodStatic member CreateResourceKey Creates a resource key for the specified type and member name.
Public methodStatic member FindResource Locates a resource with the specified key.
Public methodStatic member Refresh Updates the adorner resource dictionary.
Public methodStatic member RegisterResources Registers a callback that can provide a resource dictionary.
Public methodStatic member TryFindResource Locates a resource with the specified key.

Top

Remarks

AdornerResources is a static class that is used similarly to the way SystemColors is used. Values stored in the resource table are updated when accessibility features, such as high contrast, are enabled.

Examples

AdornerResources should be used in conjunction with another static class. This second class should contain public static read-only properties for the resource keys and resource values, as in the following example:

public static class MyColors {
    private static ResourceKey _foregroundKey = AdornerResources.CreateResourceKey(typeof(MyColors), "ForegroundKey");
    
    static MyColors() {
        AdornerResources.RegisterResources(delegate {
            return new MyColorsResources();
        });
    } 
    
    public static ResourceKey ForegroundKey {
        get { return _foregroundKey; }
    }
    
    public static Brush ForegroundBrush {
        get {
            return (Brush)AdornerResources.FindResource(ForegroundKey);
        }
    }
}

The MyColorsResources class is a resource dictionary that contains the resources keyed by the MyColors static properties. If the values of the dictionary need to be dynamic, those values can be obtained by also using static keys to a property. Using MyColors in XAML can be done in the following way:

Rectangle Fill = "{DynamicResource {x:Static MyColors.ForegroundKey}}"

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.Windows.Design.Interaction Namespace

Other Resources

WPF Designer Extensibility

Adorner Architecture

Creating Custom Adorners