Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converters for resources #15688

Open
styris-ame opened this issue May 11, 2024 · 2 comments
Open

Converters for resources #15688

styris-ame opened this issue May 11, 2024 · 2 comments

Comments

@styris-ame
Copy link

Is your feature request related to a problem? Please describe.

See the following XAML that uses a binding:

<TextBlock Text="Example">
    <TextBlock.Foreground>
        <SolidColorBrush Opacity="0.5" Color="{Binding ExampleBrush, Converter={StaticResource ToColorConverter}}"/>
    </TextBlock.Foreground>
</TextBlock>

I can use the ToColorConverter to convert extract the Color property from ExampleBrush.

However, I cannot do the same with a resource:

<TextBlock Text="Example">
    <TextBlock.Foreground>
        <SolidColorBrush Opacity="0.5" Color="{DynamicResource ExampleBrush, Converter={StaticResource ToColorConverter}}"/>
    </TextBlock.Foreground>
</TextBlock>

This is particularly annoying when using themes, as I am forced to define both a SolidColorBrush and a Color for certain things.

Describe the solution you'd like

The ability to use converters with resources, or else an easy way to use a SolidColorBrush resource as a Color.

Describe alternatives you've considered

Defining a Color and a SolidColorBrush for the same actual color.

Additional context

Avalonia 11.1.0-beta2

@timunie
Copy link
Contributor

timunie commented May 12, 2024

Can you try if that would work for you? Not sure rn but worth a try. {Binding Source={DynamicResource ...}, Converter='...'}

@styris-ame
Copy link
Author

Can you try if that would work for you? Not sure rn but worth a try. {Binding Source={DynamicResource ...}, Converter='...'}

It says {DynamicResource} can only be used with dependency property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants