Linux - Invalid Window.ClientSize on startup
See original GitHub issueIssue
On Linux Window.ClientSize is invalid on startup only. This is the root cause of WindowStartupLocation = Owner/CenterScreen is not working on Linux (Related #3454).
Repro:
XAML
<Window
x:Class="AvaloniaApplication1.Views.MainWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:AvaloniaApplication1.ViewModels;assembly=AvaloniaApplication1"
Title="AvaloniaApplication1"
Width="450"
Height="450"
Icon="/Assets/avalonia-logo.ico"
mc:Ignorable="d">
<Grid>
<StackPanel>
<Button Width="200" Height="100" Name="BtnClick" Content="Refresh" />
<TextBlock Name="Txtblock"/>
</StackPanel>
</Grid>
</Window>
In Code
public MainWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
this.Opened += MainWindow_Opened;
}
private void MainWindow_Opened(object sender, System.EventArgs e)
{
var txt = this.Find<TextBlock>("Txtblock");
var sb = new StringBuilder();
sb.AppendLine($"ClientSize.Width:{ClientSize.Width}");
sb.AppendLine($"ClientSize.Height:{ClientSize.Height}");
sb.AppendLine($"this.Width:{Width}");
sb.AppendLine($"this.Height:{Height}");
sb.AppendLine();
txt.Text = sb.ToString();
}
public void Button_Clicked(object sender, RoutedEventArgs e)
{
MainWindow_Opened(null, null);
}
Opened Event - Result (Linux vs Windows):

After clicking refresh - Result (Linux only)

Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
rdesktop failing with BadWindow (invalid Window parameter)
I'm using xmonad.org window manager, which might also contribute to some less standard GUI environment. linux · xmonad · rdesktop · Share.
Read more >Steam doesn't open up / Newbie Corner ...
When I run steam, the only thing I see is the "Updating steam.." window for 1 second, which is all in blue for...
Read more >Linux: Minecraft Launcher doesnt launch any other Version ...
When I created another Launch option, and selected any other gameversion beside the latest one and want to launch it, the launcher shows...
Read more >[RESOLVED!!] Some steam games just open and close
A few days ago, I noticed that starting Noita, it would act as if opening, then close immediately, without opening a window.
Read more >Steam Proton games not starting : r/linux_gaming
I am running endeavourOS and I can't get non-native games to start, but I can get games like Factorio or CS:GO to start....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For now I think we should do
hack to mitigate autosizing issues for most X11 systems.
This issue also affects SizeToContent to not work correctly. Both makes simulating a messagebox really annoying on Linux. It always shows up at the top left corner and needs to be resized by the user.
Is there a quick workaround possible? Perhaps waiting for X11 to be finished and then resize / apply startup location?!