1+ // Copyright (c) 2024 Files Community
2+ // Licensed under the MIT License. See the LICENSE.
3+
14using Files . App . ViewModels . Previews ;
25using Microsoft . UI . Xaml ;
36using Microsoft . UI . Xaml . Controls ;
4- using Vanara . PInvoke ;
57using Windows . Foundation ;
8+ using Windows . Win32 . Foundation ;
69
710namespace Files . App . UserControls . FilePreviews
811{
@@ -13,13 +16,15 @@ public sealed partial class ShellPreview : UserControl
1316 public ShellPreview ( ShellPreviewViewModel model )
1417 {
1518 ViewModel = model ;
16- this . InitializeComponent ( ) ;
19+
20+ InitializeComponent ( ) ;
1721 }
1822
1923 private void PreviewHost_Loaded ( object sender , RoutedEventArgs e )
2024 {
2125 ViewModel . LoadPreview ( contentPresenter ) ;
2226 ViewModel . SizeChanged ( GetPreviewSize ( ) ) ;
27+
2328 if ( XamlRoot . Content is FrameworkElement element )
2429 {
2530 element . SizeChanged += PreviewHost_SizeChanged ;
@@ -38,11 +43,13 @@ private RECT GetPreviewSize()
3843 var physicalSize = contentPresenter . RenderSize ;
3944 var physicalPos = source . TransformPoint ( new Point ( 0 , 0 ) ) ;
4045 var scale = XamlRoot . RasterizationScale ;
41- var result = new RECT ( ) ;
42- result . Left = ( int ) ( physicalPos . X * scale + 0.5 ) ;
43- result . Top = ( int ) ( physicalPos . Y * scale + 0.5 ) ;
44- result . Width = ( int ) ( physicalSize . Width * scale + 0.5 ) ;
45- result . Height = ( int ) ( physicalSize . Height * scale + 0.5 ) ;
46+
47+ var result = RECT . FromXYWH (
48+ ( int ) ( physicalPos . X * scale + 0.5 ) ,
49+ ( int ) ( physicalPos . Y * scale + 0.5 ) ,
50+ ( int ) ( physicalSize . Width * scale + 0.5 ) ,
51+ ( int ) ( physicalSize . Height * scale + 0.5 ) ) ;
52+
4653 return result ;
4754 }
4855
@@ -53,6 +60,7 @@ private void PreviewHost_Unloaded(object sender, RoutedEventArgs e)
5360 element . SizeChanged -= PreviewHost_SizeChanged ;
5461 element . PointerEntered -= PreviewHost_PointerEntered ;
5562 }
63+
5664 ViewModel . UnloadPreview ( ) ;
5765 }
5866
0 commit comments