We're stuck on an issue about the appropriate use of SizeToContent=WidthandHeight and WindowStartupLocation=CenterScreen in WPF. After resizing, our window has strange black border and it is not at the center.
Conflict in using SizeToContent=widthandHeight and WindowStartupLocation in WPF
1.1k Views Asked by Aidanpraid At
3
There are 3 best solutions below
0
On
The code does not work until MaxWith and MaxHeight is given. To fix this, I used the RestoreBounds instead:
var previosWidth = this.RestoreBounds.Width;
var previosHeight = this.RestoreBounds.Height;
0
On
Approved solution worked for me but I could sometimes spot the black border for a microsecond. Was playing little bit and found this fixing it.
DialogWindow.xaml
<Window ...
WindowStartupLocation="CenterOwner"
SizeToContent="WidthAndHeight"
SnapsToDevicePixels="True"
...
DialogWindow.xaml.cs
protected override void OnActivated(EventArgs e)
{
InvalidateMeasure();
base.OnActivated(e);
}
We have solved it with this class. You should use it instead of common Window.