Search code examples
c#.netavaloniaui

DefaultStyleKeyProperty.OverrideMetadata in Avalonia UI?


In WPF, when deriving a control from a base control, you add this in the constructor.

DefaultStyleKeyProperty.OverrideMetadata(typeof(MediaPlayer), new StyledPropertyMetadata(typeof(MediaPlayer)));

How do you convert this to Avalonia UI?


Solution

  • Implement IStyleable interface and set StyleKey to your type.

    public class MyGrid : Grid, IStyleable
    {
        Type IStyleable.StyleKey => typeof(MyGrid);
    }