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

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

Open
ossandust opened this issue Jan 12, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ossandust
Copy link

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 ossandust added the bug Something isn't working label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant