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

ComboBox: support different DataTemplate for selected item. #15420

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

rabbitism
Copy link
Contributor

@rabbitism rabbitism commented Apr 17, 2024

What does the pull request do?

Add a new Property SelectedItemTemplate, if set, it has a higher priority than ItemTemplate.

What is the current behavior?

Displayed selected item is always the same as ComboBoxItem

What is the updated/expected behavior with this PR?

Make it possible to use different DataTemplates for selected item and other items.

image

How was the solution implemented (if it's not obvious)?

Use multibinding and select the first valid IDataTemplate.

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0047383-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul
Copy link
Member

MrJul commented Apr 18, 2024

Can we please call this SelectionBoxItemTemplate (same name as WPF, even if it's read-only there)?

My first thought while reading this PR was that the SelectedItemTemplate property also applies to the selected item inside the dropdown, which it doesn't.

@rabbitism
Copy link
Contributor Author

Updated according to reviews.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0047453-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@Gillibald
Copy link
Contributor

Other controls call this property ContentTemplate

@rabbitism rabbitism requested a review from maxkatz6 April 20, 2024 14:52
@maxkatz6 maxkatz6 added this pull request to the merge queue Apr 22, 2024
@maxkatz6 maxkatz6 added the backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch label Apr 22, 2024
Merged via the queue into AvaloniaUI:master with commit edb66a7 Apr 22, 2024
10 checks passed
maxkatz6 pushed a commit that referenced this pull request Apr 24, 2024
* feat: ComboBox: support different DataTemplate for selected item.

* feat: use coerce instead of multi binding.

* test: add multiple unit tests.
@maxkatz6 maxkatz6 added backported-11.1.x and removed backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants