-
Notifications
You must be signed in to change notification settings - Fork 675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Right aligned ComboBox popup drastically shifts to the right on opened #9567
Comments
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you! Open similar issues:
Closed similar issues:
|
Setting the placeholder text to the current selection works as well - when the popup opens, the width seems to be measured based on the placeholder. Why |
For anyone suffering from this behavior (original credit: Discord user // Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.Foundation;
namespace Files.App.UserControls
{
public class ComboBoxEx : ComboBox
{
double _cachedWidth;
protected override void OnDropDownOpened(object e)
{
Width = _cachedWidth;
base.OnDropDownOpened(e);
}
protected override void OnDropDownClosed(object e)
{
Width = double.NaN;
base.OnDropDownClosed(e);
}
protected override Size MeasureOverride(Size availableSize)
{
var baseSize = base.MeasureOverride(availableSize);
if (baseSize.Width != 64)
_cachedWidth = baseSize.Width;
return baseSize;
}
}
} |
What is happening here is that when the combobox is opened, the currently selected item is moved into the popup menu so that it can be shown there. But since it was removed from the main part of the ComboBox, that can cause the ComboBox to re-layout at a smaller size and so you get this jarring behavior. ComboBox should maintain its width when it opens its popup to prevent this issue from happening. The "ComboBoxEx" workaround proposed does that. Another workaround here would be to set a MinWidth on the ComboBox so that it maintains its size regardless of the selected item. |
Describe the bug
When you align ComBoBox to the right and open its popup, it is opened at a wrong position with the minimum width that includes chevron and its padding.
When I tried with the event of OnSelectionChanged and OnSizeChanged, those didn’t work.
However, a guy at UWP Community made it work, overriding MeasureOverride method and setting base width.
Steps to reproduce the bug
Expected behavior
ComboBox Opens its pop up with the item width.
Screenshots
NuGet package version
WinUI 3 - Windows App SDK 1.5.2: 1.5.240404000
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
The text was updated successfully, but these errors were encountered: