Skip to content
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

Open
0x5bfa opened this issue Apr 22, 2024 · 4 comments
Open
Labels
area-ComboBox area-Flyouts bug Something isn't working team-Controls Issue for the Controls team

Comments

@0x5bfa
Copy link

0x5bfa commented Apr 22, 2024

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

  1. Add a ComboBox
  2. Align to the right
  3. Open its pop up

Expected behavior

ComboBox Opens its pop up with the item width.

Screenshots

IMG_0084
IMG_0085

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

@0x5bfa 0x5bfa added the bug Something isn't working label Apr 22, 2024
Copy link

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:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Apr 22, 2024
@codendone codendone added area-ComboBox area-Flyouts team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Apr 26, 2024
@YourOrdinaryCat
Copy link

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 ComboBox behaves this way is beyond me, but that's the workaround I'll be using for now.

@0x5bfa
Copy link
Author

0x5bfa commented May 6, 2024

For anyone suffering from this behavior (original credit: Discord user @metrorail):

// 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;
		}
	}
}

@kmahone
Copy link
Member

kmahone commented May 7, 2024

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.

YourOrdinaryCat added a commit to YourOrdinaryCat/Charmy that referenced this issue May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ComboBox area-Flyouts bug Something isn't working team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

4 participants