Repository navigation
Open
Labels
area-BindingbugSomething isn't workingteam-CoreParent label for issues owned by the Reach, Rendering, or Markup teamsteam-MarkupIssue for the Markup team
Description
Describe the bug
The application crash when using x:Bind to set the StateTrigger.IsActive property.
Steps to reproduce the bug
Add the following XAML code in the MainWindow XAML of a blank WinAppSDK C# app:
<StackPanel>
<ToggleButton
x:Name="toggleStates"
Content="Toggle states"
IsChecked="False" />
<TextBlock x:Name="toggleStatus" Text="Off" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<StateTrigger IsActive="{x:Bind toggleStates.IsChecked.Value, Mode=OneWay}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="toggleStatus.Text" Value="On" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</StackPanel>Run the application.
It crashes at startup because the StateTrigger instance is null in
private static class XamlBindingSetters
{
public static void Set_Microsoft_UI_Xaml_StateTrigger_IsActive(global::Microsoft.UI.Xaml.StateTrigger obj, global::System.Boolean value)
{
obj.IsActive = value; // <-- obj is null
}
};Expected behavior
The generated code should work as in UWP apps where this was working without any issue.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.5.1: 1.5.240311000
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
Reacted by Carl Scarlett
Metadata
Metadata
Assignees
Labels
area-BindingbugSomething isn't workingteam-CoreParent label for issues owned by the Reach, Rendering, or Markup teamsteam-MarkupIssue for the Markup team
Type
Projects
- StatusShow more project fieldsBacklog

Activity
KWodarczyk commentedon Oct 24, 2024
This will not work in Window you need a Page
michael-hawker commentedon Nov 27, 2024
Vincent (@vgromfeld) did you try elsewhere?
Otherwise I guess it's related to #5515
WamWooWam commentedon Jan 2, 2025
I've had this exact problem using VisualStateManager in ContentTemplates myself, trying to use
x:Bindto enableStateTriggers. Notably, non-compiled bindings work just fine.This is not a Page vs. Window issue, and applies to WinUI and UWP.
WamWooWam commentedon Jan 2, 2025
Appears to be identical to #2572 but in C#