Skip to content

Commit 7d46c1c

Browse files
committed
Fix some dpi bugs
1 parent 69a3fe1 commit 7d46c1c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

MaterialDesignThemes.Wpf/ComboBoxPopup.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,33 @@ private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(Size popupSi
105105
Point offset)
106106
{
107107
var locationFromScreen = this.PlacementTarget.PointToScreen(new Point(0, 0));
108-
109-
int locationX = (int)locationFromScreen.X % (int)DpiHelper.TransformToDeviceX(SystemParameters.PrimaryScreenWidth);
110-
int locationY = (int)locationFromScreen.Y % (int)DpiHelper.TransformToDeviceY(SystemParameters.PrimaryScreenHeight);
111108

112109
var mainVisual = TreeHelper.FindMainTreeVisual(this.PlacementTarget);
110+
111+
int screenWidth = (int) DpiHelper.TransformToDeviceX(mainVisual, SystemParameters.PrimaryScreenWidth);
112+
int screenHeight = (int) DpiHelper.TransformToDeviceY(mainVisual, SystemParameters.PrimaryScreenHeight);
113+
114+
int locationX = (int)locationFromScreen.X % screenWidth;
115+
int locationY = (int)locationFromScreen.Y % screenHeight;
116+
113117
double realOffsetX = (popupSize.Width - targetSize.Width) / 2.0;
114118
double offsetX = DpiHelper.TransformToDeviceX(mainVisual, offset.X);
115119
double defaultVerticalOffsetIndepent = DpiHelper.TransformToDeviceY(mainVisual, DefaultVerticalOffset);
116120
double upVerticalOffsetIndepent = DpiHelper.TransformToDeviceY(mainVisual, UpVerticalOffset);
117121
double downVerticalOffsetIndepent = DpiHelper.TransformToDeviceY(mainVisual, DownVerticalOffset);
118122

119-
if (locationX + popupSize.Width - realOffsetX > SystemParameters.PrimaryScreenWidth
123+
if (locationX + popupSize.Width - realOffsetX > screenWidth
120124
|| locationX + realOffsetX < 0)
121125
{
122126
SetChildTemplateIfNeed(DefaultContentTemplate);
123127

124-
double newY = locationY + popupSize.Height > SystemParameters.PrimaryScreenHeight
128+
double newY = locationY + popupSize.Height > screenHeight
125129
? -(defaultVerticalOffsetIndepent + popupSize.Height)
126130
: defaultVerticalOffsetIndepent + targetSize.Height;
127131

128132
return new[] { new CustomPopupPlacement(new Point(offsetX, newY), PopupPrimaryAxis.Horizontal) };
129133
}
130-
else if (locationY + popupSize.Height > SystemParameters.PrimaryScreenHeight)
134+
else if (locationY + popupSize.Height > screenHeight)
131135
{
132136
SetChildTemplateIfNeed(UpContentTemplate);
133137

MaterialDesignToolkit.Wpf.sln.vsext.disable

Whitespace-only changes.

0 commit comments

Comments
 (0)