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

Setting certain controls in VisualState crash the app #10264

Open
HO-COOH opened this issue Dec 31, 2024 · 0 comments
Open

Setting certain controls in VisualState crash the app #10264

HO-COOH opened this issue Dec 31, 2024 · 0 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@HO-COOH
Copy link

HO-COOH commented Dec 31, 2024

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
  <StackPanel
      HorizontalAlignment="Center"
      VerticalAlignment="Center"
      Orientation="Vertical">
      <ComboBox Header="Select state:" SelectionChanged="ComboBox_SelectionChanged">
          <x:String>State1</x:String>
          <x:String>State2</x:String>
      </ComboBox>

      <ContentPresenter x:Name="Presenter" />

      <VisualStateManager.VisualStateGroups>
          <VisualStateGroup>
              <VisualState x:Name="State1">
                  <VisualState.Setters>
                      <Setter Target="Presenter.Content">
                          <Setter.Value>
                              <CalendarView />
                          </Setter.Value>
                      </Setter>
                  </VisualState.Setters>
              </VisualState>

              <VisualState x:Name="State2">
                  <VisualState.Setters>
                      <Setter Target="Presenter.Content">
                          <Setter.Value>
                              <Button
                                  x:Name="State2Button"
                                  Click="State2Button_Click"
                                  Content="State 2 Button" />
                          </Setter.Value>
                      </Setter>
                  </VisualState.Setters>
              </VisualState>
          </VisualStateGroup>
      </VisualStateManager.VisualStateGroups>
  </StackPanel>
  1. In code behind, you simply switch states according to the selected ComboBox item.
        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<winrt::Microsoft::UI::Xaml::Controls::ComboBox>().SelectedItem().as<winrt::hstring>(),
                false
            ));
        }
  1. 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

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

@HO-COOH HO-COOH added the bug Something isn't working label Dec 31, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant