Skip to content

Commit d788185

Browse files
committed
Fixed issue with the combo box popup not being displayed correctly multiple monitor setup.
The screen class is a port from WinForms and updated to C# 7 and be WPF friendly.
1 parent a07f19f commit d788185

File tree

3 files changed

+418
-7
lines changed

3 files changed

+418
-7
lines changed

MaterialDesignThemes.Wpf/ComboBoxPopup.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4-
using System.Diagnostics;
54
using System.Linq;
65
using System.Windows;
76
using System.Windows.Controls;
87
using System.Windows.Controls.Primitives;
9-
using System.Windows.Data;
108
using System.Windows.Media;
119

1210
namespace MaterialDesignThemes.Wpf
@@ -240,7 +238,7 @@ private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(
240238
if (ClassicMode
241239
|| data.LocationX + data.PopupSize.Width - data.RealOffsetX > data.ScreenWidth
242240
|| data.LocationX - data.RealOffsetX < 0
243-
|| (!preferUpIfSafe && (data.LocationY - Math.Abs(data.NewDownY) < 0)))
241+
|| !preferUpIfSafe && data.LocationY - Math.Abs(data.NewDownY) < 0)
244242
{
245243
SetCurrentValue(PopupPlacementProperty, ComboBoxPopupPlacement.Classic);
246244
return new[] { GetClassicPopupPlacement(this, data) };
@@ -273,11 +271,13 @@ private PositioningData GetPositioningData(IEnumerable<DependencyObject> visualA
273271
var mainVisual = visualAncestry.OfType<Visual>().LastOrDefault();
274272
if (mainVisual == null) throw new ArgumentException($"{nameof(visualAncestry)} must contains unless one {nameof(Visual)} control inside.");
275273

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);
278277

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;
281281

282282
var upVerticalOffsetIndepent = DpiHelper.TransformToDeviceY(mainVisual, UpVerticalOffset);
283283
var newUpY = upVerticalOffsetIndepent - popupSize.Height + targetSize.Height;

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
<Compile Include="Palette.cs" />
325325
<Compile Include="Plane3D.cs" />
326326
<Compile Include="ScaleHost.cs" />
327+
<Compile Include="Screen.cs" />
327328
<Compile Include="Snackbar.cs" />
328329
<Compile Include="SnackbarMessage.cs" />
329330
<Compile Include="SnackbarMessageEventArgs.cs" />

0 commit comments

Comments
 (0)