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

x:Bind not working with StateTrigger #9472

Open
vgromfeld opened this issue Mar 21, 2024 · 2 comments
Open

x:Bind not working with StateTrigger #9472

vgromfeld opened this issue Mar 21, 2024 · 2 comments
Labels
area-Binding bug Something isn't working team-Markup Issue for the Markup team

Comments

@vgromfeld
Copy link

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
    }
};

image

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

@vgromfeld vgromfeld added the bug Something isn't working label Mar 21, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Mar 21, 2024
@bpulliam bpulliam added area-Binding team-Markup Issue for the Markup team and removed needs-triage Issue needs to be triaged by the area owners labels Mar 22, 2024
@KWodarczyk
Copy link

KWodarczyk commented Oct 24, 2024

This will not work in Window you need a Page

@michael-hawker
Copy link
Collaborator

This will not work in Window you need a Page

@vgromfeld did you try elsewhere?

Otherwise I guess it's related to #5515

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Binding bug Something isn't working team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

4 participants