XAML での静的フィールドへのアクセス
-
09-06-2019 - |
質問
xaml でクラスの静的プロパティを参照するにはどうすればよいでしょうか?言い換えれば、次のようなことをしたいのです。
Class BaseThingy {
public static readonly Style BaseStyle;
...
}
<ResoureDictionary ...>
<Style BasedOn="BaseThingy.Style" TargetType="BaseThingy" />
</ResourceDictionary>
BasedOn でこれを行うための構文は何ですか?を使用する必要があると思いました StaticResource
ある程度はできましたが、私にはうまくいきませんでした。
解決
使用 x:静的 マークアップ拡張子
<ResoureDictionary ...
xmlns:local="clr-namespace:Namespace.Where.Your.BaseThingy.Class.Is.Defined"
>
<Style BasedOn="{x:Static local:BaseThingy.BaseStyle}" TargetType="BaseThingy" />
</ResourceDictionary>
所属していません StackOverflow