diff --git a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs index 646af200d362..e8d51e8536b3 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs @@ -32,9 +32,12 @@ public WpfWindowWrapper(UnoWpfWindow wpfWindow, WinUIWindow window, XamlRoot xam _wpfWindow.DpiChanged += OnNativeDpiChanged; _wpfWindow.StateChanged += OnNativeStateChanged; _wpfWindow.Host.SizeChanged += (_, e) => OnHostSizeChanged(e.NewSize); - OnHostSizeChanged(new Size(_wpfWindow.Width, _wpfWindow.Height)); _wpfWindow.LocationChanged += OnNativeLocationChanged; _wpfWindow.SizeChanged += OnNativeSizeChanged; + + RasterizationScale = (float)VisualTreeHelper.GetDpi(_wpfWindow.Host).DpiScaleX; + + OnHostSizeChanged(new Size(_wpfWindow.Width, _wpfWindow.Height)); UpdateSizeFromNative(); UpdatePositionFromNative(); } @@ -45,18 +48,18 @@ private void UpdateSizeFromNative() { if (!_wasShown) { - Size = new() { Width = (int)_wpfWindow.Width, Height = (int)_wpfWindow.Height }; + Size = new() { Width = (int)(_wpfWindow.Width * RasterizationScale), Height = (int)(_wpfWindow.Height * RasterizationScale) }; } else { - Size = new() { Width = (int)_wpfWindow.ActualWidth, Height = (int)_wpfWindow.ActualHeight }; + Size = new() { Width = (int)(_wpfWindow.ActualWidth * RasterizationScale), Height = (int)(_wpfWindow.ActualHeight * RasterizationScale) }; } } private void OnNativeLocationChanged(object? sender, EventArgs e) => UpdatePositionFromNative(); private void UpdatePositionFromNative() => - Position = new() { X = (int)_wpfWindow.Left, Y = (int)_wpfWindow.Top }; + Position = new() { X = (int)(_wpfWindow.Left * RasterizationScale), Y = (int)(_wpfWindow.Top * RasterizationScale) }; private void OnNativeStateChanged(object? sender, EventArgs e) => UpdateIsVisible(); @@ -72,7 +75,6 @@ public override string Title protected override void ShowCore() { - RasterizationScale = (float)VisualTreeHelper.GetDpi(_wpfWindow.Host).DpiScaleX; _wpfWindow.Show(); _wasShown = true; UpdatePositionFromNative(); @@ -165,8 +167,8 @@ protected override IDisposable ApplyOverlappedPresenter(OverlappedPresenter pres public override void Move(PointInt32 position) { - _wpfWindow.Left = position.X; - _wpfWindow.Top = position.Y; + _wpfWindow.Left = position.X / RasterizationScale; + _wpfWindow.Top = position.Y / RasterizationScale; if (!_wasShown) { @@ -177,8 +179,8 @@ public override void Move(PointInt32 position) public override void Resize(SizeInt32 size) { - _wpfWindow.Width = size.Width; - _wpfWindow.Height = size.Height; + _wpfWindow.Width = size.Width / RasterizationScale; + _wpfWindow.Height = size.Height / RasterizationScale; if (!_wasShown) {