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 :

After switching theme with a "secondary" command :

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.
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 :
This happens for instance with all CommandBarButton labels :


After switching theme with a "primary" command :
After switching theme with a "secondary" command :
Desktop/Platform :
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.