|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.ComponentModel;
|
4 |
| -using System.Diagnostics; |
5 | 4 | using System.Linq;
|
6 | 5 | using System.Windows;
|
7 | 6 | using System.Windows.Controls;
|
8 | 7 | using System.Windows.Controls.Primitives;
|
9 |
| -using System.Windows.Data; |
10 | 8 | using System.Windows.Media;
|
11 | 9 |
|
12 | 10 | namespace MaterialDesignThemes.Wpf
|
@@ -240,7 +238,7 @@ private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(
|
240 | 238 | if (ClassicMode
|
241 | 239 | || data.LocationX + data.PopupSize.Width - data.RealOffsetX > data.ScreenWidth
|
242 | 240 | || data.LocationX - data.RealOffsetX < 0
|
243 |
| - || (!preferUpIfSafe && (data.LocationY - Math.Abs(data.NewDownY) < 0))) |
| 241 | + || !preferUpIfSafe && data.LocationY - Math.Abs(data.NewDownY) < 0) |
244 | 242 | {
|
245 | 243 | SetCurrentValue(PopupPlacementProperty, ComboBoxPopupPlacement.Classic);
|
246 | 244 | return new[] { GetClassicPopupPlacement(this, data) };
|
@@ -273,11 +271,13 @@ private PositioningData GetPositioningData(IEnumerable<DependencyObject> visualA
|
273 | 271 | var mainVisual = visualAncestry.OfType<Visual>().LastOrDefault();
|
274 | 272 | if (mainVisual == null) throw new ArgumentException($"{nameof(visualAncestry)} must contains unless one {nameof(Visual)} control inside.");
|
275 | 273 |
|
276 |
| - var screenWidth = (int)DpiHelper.TransformToDeviceX(mainVisual, SystemParameters.PrimaryScreenWidth); |
277 |
| - var screenHeight = (int)DpiHelper.TransformToDeviceY(mainVisual, SystemParameters.PrimaryScreenHeight); |
| 274 | + var screen = Screen.FromPoint(locationFromScreen); |
| 275 | + var screenWidth = (int)DpiHelper.TransformToDeviceX(mainVisual, (int)screen.Bounds.Width); |
| 276 | + var screenHeight = (int)DpiHelper.TransformToDeviceY(mainVisual, (int)screen.Bounds.Height); |
278 | 277 |
|
279 |
| - var locationX = (int)locationFromScreen.X % screenWidth; |
280 |
| - var locationY = (int)locationFromScreen.Y % screenHeight; |
| 278 | + //Adjust the location to be in terms of the current screen |
| 279 | + var locationX = (int)locationFromScreen.X % screenWidth - screen.Bounds.X; |
| 280 | + var locationY = (int)locationFromScreen.Y % screenHeight - screen.Bounds.Y; |
281 | 281 |
|
282 | 282 | var upVerticalOffsetIndepent = DpiHelper.TransformToDeviceY(mainVisual, UpVerticalOffset);
|
283 | 283 | var newUpY = upVerticalOffsetIndepent - popupSize.Height + targetSize.Height;
|
|
0 commit comments