Commit dd703ff
[windows] Fixed Rapid change of selected tab results in crash. (#33113)
### Root Cause
On Windows, `TabbedPage` uses WinUI `Frame` navigation to display each
tab’s content. Each tab’s platform view (native UI element) is hosted
inside a WinUI `Page` through a `ContentPresenter`.
During rapid tab switching, the platform view is reassigned to a new
WinUI `Page` while still attached to the previous one. WinUI does not
allow a UI element to exist in two visual trees simultaneously, which
causes the crash.
### Description of Change
Added a `_displayedPage` tracking field to maintain the correct
displayed MAUI Page during navigation, allowing `NavigateToPage` to skip
early if the requested page is already displayed and avoid redundant
navigation. The method also now clears the previous WinUI Page’s
`ContentPresenter` to explicitly detach the platform view and prevent
the “element already has a parent” WinUI error. In
`UpdateCurrentPageContent`, a skip guard avoids reassigning content that
is already set, while `_displayedPage` is updated only after successful
content assignment. Finally, OnHandlerDisconnected resets
`_displayedPage` to null to ensure proper cleanup and prevent stale
references.
### Issues Fixed
Fixes #32824
Tested the behaviour in the following platforms
- [x] Android
- [x] Windows
- [x] iOS
- [x] Mac
### Output Video
| Before Issue Fix | After Issue Fix |
|------------------|-----------------|
| <img width="350" alt="withoutfix"
src="https://github.com/user-attachments/assets/4ae17a81-a399-4cd6-856d-ca4938cb683b"
/> | <img width="350" alt="withfix"
src="https://github.com/user-attachments/assets/5927a164-22d8-45bc-a910-003bfbc1927a"
/> |1 parent b611772 commit dd703ff
2 files changed
Lines changed: 50 additions & 2 deletions
File tree
- src/Controls
- src/Core/TabbedPage
- tests/DeviceTests/Elements/TabbedPage
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| 181 | + | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
| |||
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
258 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
259 | 267 | | |
| 268 | + | |
260 | 269 | | |
261 | 270 | | |
262 | 271 | | |
| |||
270 | 279 | | |
271 | 280 | | |
272 | 281 | | |
273 | | - | |
| 282 | + | |
274 | 283 | | |
275 | 284 | | |
276 | 285 | | |
| |||
297 | 306 | | |
298 | 307 | | |
299 | 308 | | |
| 309 | + | |
300 | 310 | | |
301 | 311 | | |
302 | 312 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
197 | 201 | | |
198 | 202 | | |
199 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
200 | 238 | | |
201 | 239 | | |
0 commit comments