Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing static fields in XAML

How does one go about referencing a class's static properties in xaml? In other words, I want to do something like this:

Class BaseThingy {
  public static readonly Style BaseStyle;
  ...
}
<ResoureDictionary ...>
  <Style BasedOn="BaseThingy.Style" TargetType="BaseThingy" />
</ResourceDictionary>

What is the syntax to do this in the BasedOn? I assumed it would involve using StaticResource to some degree, but I haven't gotten it to work for me.

like image 460
MojoFilter Avatar asked Dec 22 '22 14:12

MojoFilter


1 Answers

Use x:Static markup extension

<ResoureDictionary ...
  xmlns:local="clr-namespace:Namespace.Where.Your.BaseThingy.Class.Is.Defined"
>
  <Style BasedOn="{x:Static local:BaseThingy.BaseStyle}" TargetType="BaseThingy" />
</ResourceDictionary>
like image 191
aku Avatar answered Dec 27 '22 23:12

aku