@@ -106,44 +106,45 @@ private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(Size popupSi
106
106
{
107
107
var locationFromScreen = this . PlacementTarget . PointToScreen ( new Point ( 0 , 0 ) ) ;
108
108
109
- var mainVisual = TreeHelper . FindMainTreeVisual ( this . PlacementTarget ) ;
109
+ var mainVisual = PlacementTarget . GetVisualAncestory ( ) . OfType < System . Windows . Media . Visual > ( ) . LastOrDefault ( ) ;
110
+ if ( mainVisual == null ) return new CustomPopupPlacement [ 0 ] ;
110
111
111
- int screenWidth = ( int ) DpiHelper . TransformToDeviceX ( mainVisual , SystemParameters . PrimaryScreenWidth ) ;
112
- int screenHeight = ( int ) DpiHelper . TransformToDeviceY ( mainVisual , SystemParameters . PrimaryScreenHeight ) ;
112
+ var screenWidth = ( int ) DpiHelper . TransformToDeviceX ( mainVisual , SystemParameters . PrimaryScreenWidth ) ;
113
+ var screenHeight = ( int ) DpiHelper . TransformToDeviceY ( mainVisual , SystemParameters . PrimaryScreenHeight ) ;
113
114
114
- int locationX = ( int ) locationFromScreen . X % screenWidth ;
115
- int locationY = ( int ) locationFromScreen . Y % screenHeight ;
115
+ var locationX = ( int ) locationFromScreen . X % screenWidth ;
116
+ var locationY = ( int ) locationFromScreen . Y % screenHeight ;
116
117
117
- double realOffsetX = ( popupSize . Width - targetSize . Width ) / 2.0 ;
118
- double offsetX = DpiHelper . TransformToDeviceX ( mainVisual , offset . X ) ;
119
- double defaultVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , DefaultVerticalOffset ) ;
120
- double upVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , UpVerticalOffset ) ;
121
- double downVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , DownVerticalOffset ) ;
118
+ var realOffsetX = ( popupSize . Width - targetSize . Width ) / 2.0 ;
119
+ var offsetX = DpiHelper . TransformToDeviceX ( mainVisual , offset . X ) ;
120
+ var defaultVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , DefaultVerticalOffset ) ;
121
+ var upVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , UpVerticalOffset ) ;
122
+ var downVerticalOffsetIndepent = DpiHelper . TransformToDeviceY ( mainVisual , DownVerticalOffset ) ;
122
123
123
124
if ( locationX + popupSize . Width - realOffsetX > screenWidth
124
125
|| locationX + realOffsetX < 0 )
125
126
{
126
127
SetChildTemplateIfNeed ( DefaultContentTemplate ) ;
127
128
128
- double newY = locationY + popupSize . Height > screenHeight
129
+ var newY = locationY + popupSize . Height > screenHeight
129
130
? - ( defaultVerticalOffsetIndepent + popupSize . Height )
130
131
: defaultVerticalOffsetIndepent + targetSize . Height ;
131
132
132
133
return new [ ] { new CustomPopupPlacement ( new Point ( offsetX , newY ) , PopupPrimaryAxis . Horizontal ) } ;
133
134
}
134
- else if ( locationY + popupSize . Height > screenHeight )
135
+ if ( locationY + popupSize . Height > screenHeight )
135
136
{
136
137
SetChildTemplateIfNeed ( UpContentTemplate ) ;
137
138
138
- double newY = upVerticalOffsetIndepent - popupSize . Height + targetSize . Height ;
139
+ var newY = upVerticalOffsetIndepent - popupSize . Height + targetSize . Height ;
139
140
140
141
return new [ ] { new CustomPopupPlacement ( new Point ( offsetX , newY ) , PopupPrimaryAxis . None ) } ;
141
142
}
142
143
else
143
144
{
144
145
SetChildTemplateIfNeed ( DownContentTemplate ) ;
145
146
146
- double newY = downVerticalOffsetIndepent ;
147
+ var newY = downVerticalOffsetIndepent ;
147
148
148
149
return new [ ] { new CustomPopupPlacement ( new Point ( offsetX , newY ) , PopupPrimaryAxis . None ) } ;
149
150
}
0 commit comments