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
SelectableTextBlock does not update theme correctly if it contains a LineBreak #12404
Comments
I tested this again and it looks like what's actually happening is the text color is using the opposite color of what it should be. When switching to light theme the text color is white, when switching to dark theme the text color is black. So this might just be a case of the wrong color being used to update the text color? I don't see any XAML definition for TextBlock and SelectableTextBlock doesn't specify a color for the foreground color so maybe it's inheriting the background color here? Assuming i understand themes correctly: Would adding a definition in the relevant XAML file fix this? |
@SamVanheer you can give it a try by cloning the source and add a test case into src/samples/Sandbox. Then add the xaml as suggested and test if that fixes the issue. If yes, a PR is welcome imo. |
I tried that, it's not the XAML that's at fault. I traced through the code to see what's happening and i think i've found the problem. This is where the color is passed into the Avalonia/src/Avalonia.Controls/TextBlock.cs Lines 631 to 665 in e49d61a
If a What needs to happen here is the |
@SamVanheer thx for looking into. Maybe this helps @Gillibald to find the root cause here |
I've managed to find a workaround that involves doing this after changing the theme: Dispatcher.UIThread.Post(() =>
{
DescriptionText.IsVisible = false;
DescriptionText.IsVisible = true;
}); Obviously this isn't a great way to deal with the problem but as a temporary workaround it should suffice. I think this works because the element redraws itself before it updates itself. For some reason the update doesn't trigger another redraw operation. |
Describe the bug
If you have a
SelectableTextBlock
with aLineBreak
in it, changing the application theme usingApplication.Current.RequestedThemeVariant
does not update the text block theme. It only updates when the block is clicked on.To Reproduce
Create a window containing this XAML:
Add a method of changing the theme at runtime, build and run and change the theme.
Expected behavior
The theme updates immediately when changed.
Screenshots
Desktop (please complete the following information):
Additional context
A minimal reproduction can be found here: https://github.com/SamVanheer/AvaloniaSelectableTextBlockBug
The text was updated successfully, but these errors were encountered: