Welcome to the .NET MAUI feedback portal. We’re happy you’re here! If you have feedback on how to improve the .NET MAUI, we’d love to hear it!>
Thanks for joining our community and helping improve Syncfusion products!
My goal is to have the dropdown auto-size the width and height based on the dropdown items while ensuring the dropdown does not get clipped by the containing page. In other words, only show scrollbars when the content would be clipped; otherwise, size the dropdown to it's content.
Although I've been able to implement this myself, it's proven to be rather convoluted:
1: Use a DataTemplateSelector for the various dropdown items being presented and use these templates to measure the height of each data type and the maximum width/height of all items. This is calculated in MeasureOverride. If items change, InvalidateMeasure.
- NOTE: To get accurate measurements, I need to create shadow items for each datatemplate, ensure the content the maximum 'size' for each value and measure each to get an accurate overall measurment. This makes setting MaxDropdownHeight overly complex for non-trivial usage and also results in duplicate measurements.
- NOTE 2: I also change the width of the SfComboBox to match the maximum item width I have calculated.
2: Track the root page (OnParentChanged) and subscribe to height change events.
- this is needed on desktop to ensure the dropdown height is adjusted.
3: Translate the X,Y coordinates where the dropdown will appear to the root page.
4: Intercept opening the dropdown and adjust MaxDropDownHeight dynamically as needed.
Proposal:
1: Provide the ability to mark the dropdown as auto size and trim to fit the containing page.
- This would completely remove the above logic.
2: Interpret MaxDropdownHeight as a limit and trim to fit the containing page.
- Providing an event or override that communicated the per-item measured size would make calculating a MaxDropdownHeight deterministic for all cases.
IMHO: I feel the dropdown being clipped by the containing page a design bug in SfComboBox that should require workarounds like above.
As an aside, when I used a DataTemplateSelector for the dropdown items, I do NOT see a scrollbar, even when it is needed. As a result, there's no visible user feedback that scrolling is needed. At this point, I haven't determined if it's an issue with my datatemplates, if my calculations for maximum item width are in error, or something else.