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

Fixed TabItem.ContentTemplate being reused for the next tab item #17141

Merged

Conversation

TomEdwardsEnscape
Copy link
Contributor

When TabControl switches between items, it first changes SelectedContent, and then changes SelectedContentTemplate. This means that there is a gap within which the content and content template can be out of sync.

What does the pull request do?

This PR determines whether SelectedContentTemplate is about to change when switching TabItem. If it is, the value is now cleared before changing either SelectedContent or SelectedContentTemplate. This avoids an unnecessary template build call and prevents the old template and any controls generated from it from ever seeing the new content object. They may not expect or support the new content object.

Breaking changes

None, unless you count the template being built with the wrong content immediately before being built again with the right content a supported feature.

Obsoletions / Deprecations

None.

@avaloniaui-bot
Copy link

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

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!
The new code path should be triggered in more situations though, see the comment below.

src/Avalonia.Controls/TabControl.cs Outdated Show resolved Hide resolved
@MrJul MrJul added the bug label Sep 26, 2024
@TomEdwardsEnscape TomEdwardsEnscape force-pushed the fixes/tabitem-contenttemplate-reused branch from bcca5bd to 3541705 Compare September 26, 2024 19:14
@avaloniaui-bot
Copy link

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

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@MrJul MrJul added this pull request to the merge queue Sep 27, 2024
Merged via the queue into AvaloniaUI:master with commit 1e34a78 Sep 27, 2024
10 checks passed
@TomEdwardsEnscape TomEdwardsEnscape deleted the fixes/tabitem-contenttemplate-reused branch September 27, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants