AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.63k stars 2.22k forks source link

Set property field in Style #7145

Open RomanSoloweow opened 2 years ago

RomanSoloweow commented 2 years ago

I can't set a value for a property field.

StyledProperty in "MyControl"

public static readonly StyledProperty<MyClass?> MyClassProperty =
    AvaloniaProperty.Register<MyControl, MyClass?>(nameof(MyClass));

public MyClass MyClass
{
    get => this.GetValue<MyClass>(MyClassProperty );
    set => SetValue(MyClassProperty , value);
}

Style:

<Style Selector="controls|MyControl">
    <Setter Property="MyClass.MyValue" Value="123"/>
</Style>

MyValue in MyClass is also StyledProperty

maxkatz6 commented 2 years ago

Won't it conflict with attached properties syntax? How it works in WPF? I don't really remember.