File tree Expand file tree Collapse file tree 4 files changed +61
-7
lines changed Expand file tree Collapse file tree 4 files changed +61
-7
lines changed Original file line number Diff line number Diff line change @@ -105,17 +105,19 @@ private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(Size popupSi
105
105
Point offset )
106
106
{
107
107
var locationFromScreen = this . PlacementTarget . PointToScreen ( new Point ( 0 , 0 ) ) ;
108
-
108
+
109
109
int locationX = ( int ) locationFromScreen . X % ( int ) DpiHelper . TransformToDeviceX ( SystemParameters . PrimaryScreenWidth ) ;
110
110
int locationY = ( int ) locationFromScreen . Y % ( int ) DpiHelper . TransformToDeviceY ( SystemParameters . PrimaryScreenHeight ) ;
111
- double realOffsetX = ( popupSize . Width - targetSize . Width ) / 2.0 ;
112
111
113
- double offsetX = DpiHelper . TransformToDeviceX ( offset . X ) ;
114
- double defaultVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( DefaultVerticalOffset ) ;
115
- double upVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( UpVerticalOffset ) ;
116
- double downVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( DownVerticalOffset ) ;
112
+ var mainVisual = TreeHelper . FindMainTreeVisual ( this . PlacementTarget ) ;
113
+ double realOffsetX = ( popupSize . Width - targetSize . Width ) / 2.0 ;
114
+ double offsetX = DpiHelper . TransformToDeviceX ( mainVisual , offset . X ) ;
115
+ double defaultVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , DefaultVerticalOffset ) ;
116
+ double upVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , UpVerticalOffset ) ;
117
+ double downVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , DownVerticalOffset ) ;
117
118
118
- if ( locationX + popupSize . Width - realOffsetX > SystemParameters . PrimaryScreenWidth || locationX + realOffsetX < 0 )
119
+ if ( locationX + popupSize . Width - realOffsetX > SystemParameters . PrimaryScreenWidth
120
+ || locationX + realOffsetX < 0 )
119
121
{
120
122
SetChildTemplateIfNeed ( DefaultContentTemplate ) ;
121
123
Original file line number Diff line number Diff line change 5
5
using System . Text ;
6
6
using System . Threading . Tasks ;
7
7
using System . Windows ;
8
+ using System . Windows . Media ;
8
9
9
10
namespace MaterialDesignThemes . Wpf
10
11
{
@@ -25,6 +26,28 @@ static DpiHelper()
25
26
_dpiY = ( int ) dpiYProperty . GetValue ( null , null ) ;
26
27
}
27
28
29
+ public static double TransformToDeviceY ( Visual visual , double y )
30
+ {
31
+ var source = PresentationSource . FromVisual ( visual ) ;
32
+ if ( source != null )
33
+ {
34
+ return y * source . CompositionTarget . TransformToDevice . M22 ;
35
+ }
36
+
37
+ return TransformToDeviceY ( y ) ;
38
+ }
39
+
40
+ public static double TransformToDeviceX ( Visual visual , double x )
41
+ {
42
+ var source = PresentationSource . FromVisual ( visual ) ;
43
+ if ( source != null )
44
+ {
45
+ return x * source . CompositionTarget . TransformToDevice . M11 ;
46
+ }
47
+
48
+ return TransformToDeviceX ( x ) ;
49
+ }
50
+
28
51
public static double TransformToDeviceY ( double y )
29
52
{
30
53
return y * _dpiY / StandartDpiY ;
Original file line number Diff line number Diff line change 277
277
<Compile Include =" RippleAssist.cs" />
278
278
<Compile Include =" Ripple.cs" />
279
279
<Compile Include =" TransitionAssist.cs" />
280
+ <Compile Include =" TreeHelper.cs" />
280
281
<Compile Include =" Underline.cs" />
281
282
<Compile Include =" ValidationAssist.cs" />
282
283
<EmbeddedResource Include =" Properties\Resources.resx" >
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+ using System . Windows ;
7
+ using System . Windows . Controls . Primitives ;
8
+ using System . Windows . Media ;
9
+
10
+ namespace MaterialDesignThemes . Wpf
11
+ {
12
+ internal static class TreeHelper
13
+ {
14
+ public static Visual FindMainTreeVisual ( Visual visual )
15
+ {
16
+ DependencyObject root = null ;
17
+ DependencyObject dependencyObject = visual ;
18
+
19
+ while ( dependencyObject != null )
20
+ {
21
+ root = dependencyObject ;
22
+ dependencyObject = VisualTreeHelper . GetParent ( dependencyObject ) ;
23
+ }
24
+
25
+ return root as Visual ;
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments