microsoft / microsoft/microsoft-ui-xaml

Setting certain controls in VisualState crash the app

Open
#10,264 0 comments 0 reactions 0 assignees View on GitHub
bug needs-triage
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

I am setting `ContentPresenter.Content` to some controls in a `VisualState`. It crashes the app on certain larger / more complex controls, but it's okay for basic `Button`.

It's kind of a weird and corner-case usage I know, but if it's by design it should be documented somewhere.

### Steps to reproduce the bug

1. Use this xaml
```xml


State1
State2























```
2. In code behind, you simply switch states according to the selected `ComboBox` item.
```cpp
void ComboBox_SelectionChanged(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& e)
{
winrt::check_bool(winrt::Microsoft::UI::Xaml::VisualStateManager::GoToState(
*this,
sender.as().SelectedItem().as(),
false
));
}
```
3. Build and run. Switch the state from the comboBox the first time, it works without issue. But switch back to the same state, it crashes.

### Expected behavior

No crash.

### Screenshots
![Image](https://github.com/user-attachments/assets/0d5be623-bee5-4522-92de-7a59a9161b50)

### NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

### Windows version

Windows 11 (23H2): Build 22631

### Additional context

This happens to UWP and WinUI3.
[Repro](https://github.com/HO-COOH/WinUI-Bug/tree/main/23-VisualStateControlCrash)

Contributor guide

Open the contributing guide

Research direction

Start with the linked 23-VisualStateControlCrash reproduction and switch repeatedly between the two VisualState values, comparing CalendarView with Button. Trace the VisualStateManager state transition and ContentPresenter content replacement; done means repeated transitions no longer crash for the reported controls, with regression coverage if an appropriate test location is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.