FluentAvalonia icon indicating copy to clipboard operation
FluentAvalonia copied to clipboard

TextAlignment wrong when switching theme from within a CommandBar secondary command

Open ossandust opened this issue 11 months ago • 2 comments

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.

ossandust avatar Jan 12 '25 11:01 ossandust

I have also encountered this under Windows with the latest versions, though for me it did affect primary command buttons. In my case I was switching color styles via a MenuItem, so the change didn't originate with the CommandBar control.

exectails avatar Jan 31 '25 13:01 exectails

I have something similar - i'm using a ColorPickerButton to change text color. When I do this, my TextBlock seems to lose the TextAlignment that is set - always ending up with TextAlignment.Left. The ViewModel still has the TextAlignment from prior to changing the color. Interestingly, If I swap out the TextBlock for a TextBox, this doesn't happen.

renrutsirhc avatar Feb 02 '25 00:02 renrutsirhc

Based on the attached Avalonia PR, this issue has been fixed. However, this appears to be an Avalonia issue anyway. Closing.

amwx avatar Sep 01 '25 20:09 amwx