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
24.34k stars 2.1k forks source link

AVLN3000: Can't use resource for Foreground property of TextPresenter #15690

Closed styris-ame closed 1 month ago

styris-ame commented 1 month ago

Describe the bug

See the following XAML using a TextPresenter:

<TextPresenter Text="Test" Foreground="{DynamicResource TextPrimaryBrush}"/>

It gives me this error upon compilation: Error AVLN3000 : Unable to find suitable setter or adder for property Foreground of type Avalonia.Controls:Avalonia.Controls.Presenters.TextPresenter for argument Avalonia.Base:Avalonia.Data.IBinding, available setter parameter lists are: Avalonia.Media.IBrush Line 68, position 97.

However I can still set the brush like this:

<TextPresenter Text="Test">
    <TextPresenter.Foreground>
        <SolidColorBrush Color="{DynamicResource TextPrimaryColor}"/>
    </TextPresenter.Foreground>
</TextPresenter>

The following works too:

<TextPresenter Text="Test" Foreground="Red"/>

I don't think this matters, but this is my brush resource:

<SolidColorBrush x:Key="TextPrimaryBrush" Color="#191a1a"/>

To Reproduce

Self explanatory

Expected behavior

No response

Avalonia version

11.1.0-beta2

OS

Windows

Additional context

I tested it on another project too, with the same result.

maxkatz6 commented 1 month ago

You can't bind to TextPresenter properties. This is a presenter control, designed to be used as a building block of more complex controls (like, TextBox).