AdornerResources 类

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

用于定义一组可在 XAML 中使用的资源。

继承层次结构

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

命名空间:  Microsoft.Windows.Design.Interaction
程序集:  Microsoft.Windows.Design.Interaction(在 Microsoft.Windows.Design.Interaction.dll 中)

语法

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

AdornerResources 类型公开以下成员。

方法

  名称 说明
公共方法静态成员 CreateResourceKey 为指定的类型和成员名称创建一个资源键。
公共方法静态成员 FindResource 查找具有指定键的资源。
公共方法静态成员 Refresh 更新装饰器资源字典。
公共方法静态成员 RegisterResources 注册一个可以提供资源字典的回调。
公共方法静态成员 TryFindResource 查找具有指定键的资源。

页首

备注

AdornerResources 是一个静态类,其使用与 SystemColors 的使用类似。 当启用辅助功能(如高对比度)时,资源表中存储的值更新。

示例

AdornerResources 应当与另一个静态类结合使用。 第二个类应包含资源键和资源值的公共静态只读属性,如下例所示:

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);
        }
    }
}

MyColorsResources 类是一个资源字典,包含以 MyColors 静态属性作为键的资源。 如果字典的值需要是动态的,则还可以使用属性的静态键来获得这些值。 在 XAML 中可以通过以下方法来使用 MyColors:

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

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参见

参考

Microsoft.Windows.Design.Interaction 命名空间

其他资源

WPF 设计器扩展性

装饰器体系结构

创建自定义装饰器