-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
ComboBox Empty Selection should not Generate a TextBlock as SelectionBoxItem #16748
Conversation
You can test this PR using the following package version. |
|
@cla-avalonia agree |
Should we expose an |
I am not sure. If so, I may implement it under this PR or a new one. |
Good catch! it's likely an oversight when The issue reproduces only when the selection has been set to a valid item before, so a unit test would be nice. I wanted to ask you to write that test, but I've already done so while checking the behavior of this PR. [Fact]
public void DisplayMemberBinding_Is_Not_Applied_To_SelectionBoxItem_Without_Selection()
{
var target = new ComboBox
{
DisplayMemberBinding = new Binding(),
ItemsSource = new[] { "foo", "bar" }
};
target.SelectedItem = null;
Assert.Null(target.SelectionBoxItem);
target.SelectedItem = "foo";
Assert.NotNull(target.SelectionBoxItem);
target.SelectedItem = null;
Assert.Null(target.SelectionBoxItem);
} |
You can test this PR using the following package version. |
Hi, @MrJul, Thank you for your reply! I have appended this code snippet to the |
You can test this PR using the following package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
…BoxItem (#16748) * ComboBox empty selection should not generate a TextBlock as SelectionBoxItem Fixes: #16747 * Add test for ComboBox DisplayMemberBinding behavior without selection. --------- Co-authored-by: Julien Lebosquain <[email protected]>
What does the pull request do?
Fixes #16747
As demonstrated in issue #16747, for a
ComboBox
, when specifyingPlaceholderText
andDisplayMemberBinding
simultaneously, the placeholder text always disappears, regardless of whether there is a selected item or not.This issue was introduced by #11227.
What is the current behavior?
When updating the selection box item in a
ComboBox
, where aDisplayMemberBinding
is set leavingItemTemplate
andSelectionBoxItemTemplate
null, aTextBlock
will be generated as theSelectionBoxItem
:Avalonia/src/Avalonia.Controls/ComboBox.cs
Lines 474 to 484 in 2d51602
The code above will always generate a non-null object of
TextBlock
assigned toSelectionBoxItem
, which causes theObjectConverters.IsNull
converter onIsVisible
of thePlaceholderTextBlock
in the control template ofComboBox
always returnsfalse
, hence, the issue.Avalonia/src/Avalonia.Themes.Fluent/Controls/ComboBox.xaml
Lines 77 to 84 in 2d51602
What is the updated/expected behavior with this PR?
The placeholder should always display when none are selected.
How was the solution implemented (if it's not obvious)?
The
SelectionBoxItem
should be set to null (the argumentitem
passed toUpdateSelectionBoxItem
in fact, but it will be anull
under this circumstance), to allow theObjectConverters.IsNull
converter to succeed in returningtrue
to let thePlaceholderTextBlock
display.Checklist
Breaking changes
Since 11.0.0-preview8, for a
ComboBox
, if theDisplayMemberBinding
is set andItemTemplate
andSelectionBoxItemTemplate
are left null, theSelectionBoxItem
will always return aTextBlock
, whoseText
will be the selected member, or a null inside aTextBlock
when none are selected.Since this PR, in the same scenario, when none are selected, the
SelectionBoxItem
will returnnull
(the passed-in argumentitem
itself) instead.Obsoletions / Deprecations
None.
Fixed issues
Fixes #16747