Skip to content

Commit 750c145

Browse files
committed
fix some problems
1 parent d84b6c7 commit 750c145

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Reflection;
34
using System.Windows;
45
using System.Windows.Controls;
56
using System.Windows.Controls.Primitives;
67
using System.Windows.Input;
8+
using System.Windows.Media;
79
using iNKORE.UI.WPF.Converters;
810
using iNKORE.UI.WPF.Modern.Controls.Primitives;
911

@@ -28,8 +30,9 @@ static WinUIComboBoxBehaviorHelper()
2830
/// 1. align selected container in popup to combobox.
2931
/// 2. in case of no selection, first in popup is highlighted (done)
3032
/// 3. mouse hovering shouldn't trigger focus ?! (done)
31-
/// 4. persist selected item only when drop down closes?? (not done)
32-
/// 5. KeepInteriorCornersSquare (already done)
33+
/// 4. KeepInteriorCornersSquare (already done)
34+
/// 5. light dismiss behavior only if click inside the window (not done)
35+
/// 6. popup bounded by the screen (not done)
3336
/// </summary>
3437
public static readonly DependencyProperty IsEnabledProperty =
3538
DependencyProperty.RegisterAttached(
@@ -99,30 +102,31 @@ private static void AlignSelectedContainer(ComboBox comboBox, Popup popup)
99102
return;
100103
}
101104

102-
var mockContainer = (comboBox.ItemContainerGenerator.ContainerFromIndex(0) as ComboBoxItem)!;
105+
var firstContainer = (comboBox.ItemContainerGenerator.ContainerFromIndex(0) as ComboBoxItem)!;
103106
var scrollViewer = GetTemplateChild<ScrollViewer>("ScrollViewer", comboBox);
104107

105-
var toSelectIndex = comboBox.SelectedIndex;
106-
if (toSelectIndex < 0)
108+
var toCenterIndex = comboBox.SelectedIndex;
109+
if (toCenterIndex < 0)
107110
{
108-
toSelectIndex = (int)Math.Ceiling(comboBox.Items.Count / 2.0);
111+
toCenterIndex = (int)Math.Ceiling(comboBox.Items.Count / 2.0);
109112
TryHighlightingFirstItem(comboBox);
110113
}
111-
else if (mockContainer.ActualHeight * comboBox.Items.Count > comboBox.MaxDropDownHeight)
114+
else if (firstContainer.ActualHeight * comboBox.Items.Count > comboBox.MaxDropDownHeight)
112115
{
113-
toSelectIndex = 0;
116+
var maxVisible = Math.Floor(comboBox.MaxDropDownHeight / firstContainer.ActualHeight);
117+
toCenterIndex = (int)Math.Floor(maxVisible / 2.0);
114118
}
115119

116120
var paddingBorder = (scrollViewer.Parent as Border)!;
117121

118122
if (IsPopupOpenDown(comboBox, popup.VerticalOffset))
119123
{
120-
popup.VerticalOffset = -mockContainer.ActualHeight * (toSelectIndex + 1) - paddingBorder.Padding.Top;
124+
popup.VerticalOffset = -firstContainer.ActualHeight * (toCenterIndex + 1) - paddingBorder.Padding.Top;
121125
}
122126
else
123127
{
124128
popup.VerticalOffset =
125-
mockContainer.ActualHeight * (Math.Min((int)(comboBox.MaxDropDownHeight / mockContainer.ActualHeight), comboBox.Items.Count) - toSelectIndex) +
129+
firstContainer.ActualHeight * (Math.Min((int)(comboBox.MaxDropDownHeight / firstContainer.ActualHeight), comboBox.Items.Count) - toCenterIndex) +
126130
paddingBorder.Padding.Bottom;
127131
}
128132
}

source/iNKORE.UI.WPF.Modern/Themes/Controls/ComboBox.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
</Rectangle>
8181
<local:ContentPresenterEx
8282
x:Name="ContentPresenter"
83+
MinHeight="20"
8384
Margin="{TemplateBinding Padding}"
8485
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
8586
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

source/iNKORE.UI.WPF.Modern/Themes/ThemeResources.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<Thickness x:Key="ComboBoxDropdownBorderThickness">1</Thickness>
6969
<Thickness x:Key="ComboBoxHeaderThemeMargin">0,0,0,4</Thickness>
7070
<Thickness x:Key="ComboBoxPopupBorderThemeThickness">2</Thickness>
71-
<Thickness x:Key="ComboBoxItemThemePadding">11,6.8,11,8.8</Thickness>
71+
<Thickness x:Key="ComboBoxItemThemePadding">11,7,11,7</Thickness>
7272
<Thickness x:Key="ComboBoxItemThemeTouchPadding">11,11,11,13</Thickness>
7373
<Thickness x:Key="ComboBoxItemThemeGameControllerPadding">11,11,11,13</Thickness>
7474
<Thickness x:Key="ComboBoxBackgroundBorderThicknessFocused">2</Thickness>

0 commit comments

Comments
 (0)