Open stogle opened 11 months ago
@stogle can you test with latest nightly the same sample? We had some text fixes in, but I don't know if that particular area was touched. So would be nice if you can confirm.
@timunie I added https://nuget-feed-nightly.avaloniaui.net/v3/index.json
to package sources, changed my "AvaloniaVersion" property to 11.1.999-cibuild0042556-beta
, deleted "bin" and "obj" folders and rebuilt. Unfortunately, I see the same results.
Thx for checking
Based on my observation that using DevTools to change the TextAlignment, then change it back again fixes the issue, I've added the following workaround to MainView.axaml.cs
:
protected override void OnLoaded(RoutedEventArgs e)
{
// Workaround for https://github.com/AvaloniaUI/Avalonia/issues/13777
foreach (var textBlock in this.GetVisualDescendants().OfType<TextBlock>())
{
TextAlignment textAlignment = textBlock.TextAlignment;
textBlock.TextAlignment = (TextAlignment)(-1);
textBlock.TextAlignment = textAlignment;
}
}
@timunie Do you have any suggestions for a less "hacky" workaround?
@stogle yeah best would be to try debugging Avalonia and send a PR if you were successful. Also maybe textBlock.InvalidateArrange()
can be called instead of manipulating the alignment...
@timunie thanks for the suggestion. InvalidateArrange()
didn't work but InvaidateMeasure()
did!
Debugging Avalonia will have to wait until I can allocate some time for that. It seems like grid length changes due to shared size scope aren't invalidating everything that should be invalidated.
The SharedSizeGroup was properly changing the Bounds of the TextBlock, making it wider, but this did not cause the TextLayout to invalidate, leaving columns with TextAlignment.Right appear left justified until something forced the redraw. We have attached a PR.
Describe the bug
TextBlocks with TextAlignment.Right that are in Grid columns with SharedSizeGroup defined are not right-aligned.
To Reproduce
Create a new Avalonia C# project targeting Desktop, using Community Toolkit, with Compiled Bindings, then make the following modifications:
MainView.axaml
:Expected behavior
TextBlocks with TextAlignment.Right should always be right-aligned.
Screenshots
Step 1 - Design view (as expected):
Step 3 - Running application (not as expected):
Step 7 - DevTools (as expected):
Step 9 - After toggling TextAlignment in DevTools (now as expected):
Environment
Additional context
The issue does not occur if
SharedSizeGroup
is not used but without it one cannot align the contents of two Grids.