Dela via


AdornerResources Class

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

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

Syntax

'Declaration
Public NotInheritable Class AdornerResources
'Usage
You do not need to declare an instance of a static class in order to access its members.
public static class AdornerResources
public ref class AdornerResources abstract sealed
public final class AdornerResources

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}}"

Inheritance Hierarchy

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

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

AdornerResources Members

Microsoft.Windows.Design.Interaction Namespace

Other Resources

WPF Designer Extensibility

Adorner Architecture

Creating Custom Adorners