Skip to content

Commit b3fe77d

Browse files
committed
better vertical offset calculation
1 parent 2b0858b commit b3fe77d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

source/iNKORE.UI.WPF.Modern/Controls/Helpers/ComboBoxHelper.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using iNKORE.UI.WPF.Modern.Common.Converters;
66
using System.Windows;
77
using System.Windows.Controls;
8+
using System.Windows.Media;
89

910
namespace iNKORE.UI.WPF.Modern.Controls.Helpers
1011
{
@@ -115,9 +116,14 @@ private static void UpdateCornerRadius(ComboBox comboBox, bool isDropDownOpen)
115116
var popup = GetTemplateChild<System.Windows.Controls.Primitives.Popup>("PART_Popup", comboBox);
116117
bool isOpenDown = GetPopupVerticalOffset(comboBox) > popup.VerticalOffset;
117118

118-
if (isOpenDown && GetTemplateChild<FrameworkElement>("PopupBorder", comboBox) is FrameworkElement childContainer)
119+
if (isOpenDown &&
120+
comboBox.ItemContainerGenerator.ContainerFromItem(comboBox.SelectedItem) is FrameworkElement itemContainer)
119121
{
120-
popup.VerticalOffset = (comboBox.SelectedIndex + 1) * -1.0 / comboBox.Items.Count * childContainer.ActualHeight;
122+
var itemTop = itemContainer.TranslatePoint(new Point(0, -itemContainer.ActualHeight + comboBox.Margin.Top + comboBox.Padding.Top), comboBox);
123+
if (itemTop.Y != 0)
124+
{
125+
popup.VerticalOffset -= itemTop.Y;
126+
}
121127
}
122128

123129
if (popup.VerticalOffset is 0)

0 commit comments

Comments
 (0)