55using iNKORE . UI . WPF . Modern . Common . Converters ;
66using System . Windows ;
77using System . Windows . Controls ;
8- using System . Windows . Threading ;
98
109namespace iNKORE . UI . WPF . Modern . Controls . Helpers
1110{
@@ -113,10 +112,20 @@ private static void UpdateCornerRadius(ComboBox comboBox, bool isDropDownOpen)
113112
114113 if ( isDropDownOpen )
115114 {
116- bool isOpenDown = IsPopupOpenDown ( comboBox ) ;
115+ var popup = GetTemplateChild < System . Windows . Controls . Primitives . Popup > ( "PART_Popup" , comboBox ) ;
116+ bool isOpenDown = IsPopupOpenDown ( comboBox , popup . VerticalOffset ) ;
117117
118- var popupRadiusFilter = isOpenDown ? CornerRadiusFilterKind . Bottom : CornerRadiusFilterKind . Top ;
119- popupRadius = CornerRadiusFilterConverter . Convert ( popupRadius , popupRadiusFilter ) ;
118+ if ( isOpenDown &&
119+ comboBox . ItemContainerGenerator . ContainerFromItem ( comboBox . SelectedItem ) is FrameworkElement itemContainer &&
120+ itemContainer . TranslatePoint ( new Point ( 0 , - itemContainer . ActualHeight + comboBox . Margin . Top + comboBox . Padding . Top ) , comboBox ) is { Y : not 0 } itemTop )
121+ {
122+ popup . VerticalOffset -= itemTop . Y ;
123+ }
124+
125+ if ( popup . VerticalOffset is 0 )
126+ {
127+ popupRadius = GetFilteredPopupRadius ( popupRadius , isOpenDown ) ;
128+ }
120129
121130 var textBoxRadiusFilter = isOpenDown ? CornerRadiusFilterKind . Top : CornerRadiusFilterKind . Bottom ;
122131 textBoxRadius = CornerRadiusFilterConverter . Convert ( textBoxRadius , textBoxRadiusFilter ) ;
@@ -148,9 +157,15 @@ private static void UpdateCornerRadius(ComboBox comboBox, bool isDropDownOpen)
148157 }
149158 }
150159
151- private static bool IsPopupOpenDown ( ComboBox comboBox )
160+ private static CornerRadius GetFilteredPopupRadius ( CornerRadius popupRadius , bool isOpenDown )
161+ {
162+ var popupRadiusFilter = isOpenDown ? CornerRadiusFilterKind . Bottom : CornerRadiusFilterKind . Top ;
163+ return CornerRadiusFilterConverter . Convert ( popupRadius , popupRadiusFilter ) ;
164+ }
165+
166+ private static bool IsPopupOpenDown ( ComboBox comboBox , double popupVerticalOffset )
152167 {
153- double verticalOffset = 0 ;
168+ double verticalOffset = popupVerticalOffset ;
154169 if ( GetTemplateChild < Border > ( c_popupBorderName , comboBox ) is Border popupBorder )
155170 {
156171 if ( GetTemplateChild < TextBox > ( c_editableTextName , comboBox ) is TextBox textBox )
@@ -159,7 +174,7 @@ private static bool IsPopupOpenDown(ComboBox comboBox)
159174 verticalOffset = popupTop . Y ;
160175 }
161176 }
162- return verticalOffset > 0 ;
177+ return verticalOffset > popupVerticalOffset ;
163178 }
164179
165180 private static object ResourceLookup ( Control control , object key )
0 commit comments