Skip to content

TextAlignment wrong when switching theme from within a CommandBar secondary command #637

@ossandust

Description

@ossandust

When switching between dark and light mode using CommandBar(Toggle)Buttons in the CommandBar.SecondaryCommands section, all text blocks with TextAlignment="Center" are rendered without text centering. The problem does not occur when the CommandBar(Toggle)Buttons are in the PrimaryCommands section.

Minimal sample to reproduce the issue :

    private void CmdDarkMode_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
    {
        Application.Current!.RequestedThemeVariant = ThemeVariant.Dark;
    }

    private void CmdLightMode_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
    {
        Application.Current!.RequestedThemeVariant = ThemeVariant.Light;
    }

<Grid RowDefinitions="auto,*">
	<ui:CommandBar >
		<ui:CommandBar.PrimaryCommands>
			<ui:CommandBarButton IconSource="WeatherMoonFilled" Label="Dark" Click="CmdDarkMode_Click"/>
			<ui:CommandBarButton IconSource="WeatherSunny" Label="Light" Click="CmdLightMode_Click"/>
		</ui:CommandBar.PrimaryCommands>
		<ui:CommandBar.SecondaryCommands>
			<ui:CommandBarButton IconSource="WeatherMoonFilled" Label="Dark theme" Click="CmdDarkMode_Click"/>
			<ui:CommandBarButton IconSource="WeatherSunny" Label="Light theme" Click="CmdLightMode_Click"/>
		</ui:CommandBar.SecondaryCommands>
	</ui:CommandBar>
	<Grid Grid.Row="1" VerticalAlignment="Center">
		<TextBlock Width="200" Margin="5" Background="LightGray" TextAlignment="Center">TEST</TextBlock>
	</Grid>
</Grid>

This happens for instance with all CommandBarButton labels :
After switching theme with a "primary" command :
image
After switching theme with a "secondary" command :
image

Desktop/Platform :

  • OS: Windows 11 + wasm
  • FluentAvalonia Version 2.2.0 (= latest)
  • Avalonia Version 11.2.3 (= latest)

Additional context
Not clear under which conditions exactly the bug occurs. For instance when removing the Grid VerticalAlignment in the minimal sample the bug does not occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions