1
+ // Copyright (c) 2024 Files Community
2
+ // Licensed under the MIT License. See the LICENSE.
3
+
1
4
using Files . App . ViewModels . Previews ;
2
5
using Microsoft . UI . Xaml ;
3
6
using Microsoft . UI . Xaml . Controls ;
4
- using Vanara . PInvoke ;
5
7
using Windows . Foundation ;
8
+ using Windows . Win32 . Foundation ;
6
9
7
10
namespace Files . App . UserControls . FilePreviews
8
11
{
@@ -13,13 +16,15 @@ public sealed partial class ShellPreview : UserControl
13
16
public ShellPreview ( ShellPreviewViewModel model )
14
17
{
15
18
ViewModel = model ;
16
- this . InitializeComponent ( ) ;
19
+
20
+ InitializeComponent ( ) ;
17
21
}
18
22
19
23
private void PreviewHost_Loaded ( object sender , RoutedEventArgs e )
20
24
{
21
25
ViewModel . LoadPreview ( contentPresenter ) ;
22
26
ViewModel . SizeChanged ( GetPreviewSize ( ) ) ;
27
+
23
28
if ( XamlRoot . Content is FrameworkElement element )
24
29
{
25
30
element . SizeChanged += PreviewHost_SizeChanged ;
@@ -38,11 +43,13 @@ private RECT GetPreviewSize()
38
43
var physicalSize = contentPresenter . RenderSize ;
39
44
var physicalPos = source . TransformPoint ( new Point ( 0 , 0 ) ) ;
40
45
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
+
46
53
return result ;
47
54
}
48
55
@@ -53,6 +60,7 @@ private void PreviewHost_Unloaded(object sender, RoutedEventArgs e)
53
60
element . SizeChanged -= PreviewHost_SizeChanged ;
54
61
element . PointerEntered -= PreviewHost_PointerEntered ;
55
62
}
63
+
56
64
ViewModel . UnloadPreview ( ) ;
57
65
}
58
66
0 commit comments