Skip to content

AppBarButton / AppBarToggleButton Do Not Properly Use the Styling System for Foreground #21016

@robloo

Description

@robloo

Describe the bug

I see code such as the following:

private void UpdateIconForeground()
{
if (Icon is IconElement icon)
{
var fg = Foreground;
if (fg != null)
icon.SetValue(ForegroundProperty, fg);
else
icon.ClearValue(ForegroundProperty);
}

This is a code smell and indicates something is incorrect with the way icons are being handled. Most of it comes from an incomplete IconElement implementation in Avalonia itself.

To Reproduce

See code:

private void UpdateIconForeground()
{
if (Icon is IconElement icon)
{
var fg = Foreground;
if (fg != null)
icon.SetValue(ForegroundProperty, fg);
else
icon.ClearValue(ForegroundProperty);
}
}

private void UpdateIconForeground()
{
if (Icon is IconElement icon)
{
var fg = Foreground;
if (fg != null)
icon.SetValue(ForegroundProperty, fg);
else
icon.ClearValue(ForegroundProperty);
}

Expected behavior

Foreground should be properly inherited without code-behind and be fully integrated with the Avalonia styling system.

Avalonia version

12.0 rc1

OS

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions