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

Change Microsoft.Xaml.Interactions.Core to Microsoft.Xaml.Interactivity #282

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

michael-hawker
Copy link
Contributor

Fixes #209

The major revision is the perfect time to fix this long-standing issue with the complexity of usings behaviors involving having to remember and include multiple namespaces in XAML. This removes the warnings from CA1020 as well.

Talked to Sergio, we think just aligning on Microsoft.Xaml.Interactivity as the main namespace would make sense (it's shorter, the more familiar name, and means the core attachment point doesn't move), this would look like this:

Before:

<Button xmlns:Core="using:Microsoft.Xaml.Interactions.Core" xmlns:Interactivity="using:Microsoft.Xaml.Interactivity">
    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="Click">
            <Core:ChangePropertyAction PropertyName="Background">
                <Core:ChangePropertyAction.Value>
                    <SolidColorBrush Color="Red"/>
                </Core:ChangePropertyAction.Value>
            </Core:ChangePropertyAction>
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</Button>

After:

<Button xmlns:Interactivity="using:Microsoft.Xaml.Interactivity">
    <Interactivity:Interaction.Behaviors>
        <Interactivity:EventTriggerBehavior EventName="Click">
            <Interactivity:ChangePropertyAction PropertyName="Background">
                <Interactivity:ChangePropertyAction.Value>
                    <SolidColorBrush Color="Red"/>
                </Interactivity:ChangePropertyAction.Value>
            </Interactivity:ChangePropertyAction>
        </Interactivity:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</Button>

For migration, folks should just be able to change the xmlns for Core:

<Button xmlns:Core="using:Microsoft.Xaml.Interactivity" xmlns:Interactivity="using:Microsoft.Xaml.Interactivity">
    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="Click">
            <Core:ChangePropertyAction PropertyName="Background">
                <Core:ChangePropertyAction.Value>
                    <SolidColorBrush Color="Red"/>
                </Core:ChangePropertyAction.Value>
            </Core:ChangePropertyAction>
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</Button>

@michael-hawker
Copy link
Contributor Author

image

Not sure why GlobalSuppression.cs is marked as a binary... opened #283

@michael-hawker
Copy link
Contributor Author

This is the suppression file before:
image

@michael-hawker
Copy link
Contributor Author

I tested and was able to build nuget packages locally and test in a File->New WinUI 3 app:

        <Button
            xmlns:i="using:Microsoft.Xaml.Interactivity"
            x:Name="myButton"
            Content="Click Me">
            <i:Interaction.Behaviors>
                <i:EventTriggerBehavior EventName="Click">
                    <i:ChangePropertyAction
                        PropertyName="Background"
                        TargetObject="{x:Bind myButton}"
                        Value="Red" />
                </i:EventTriggerBehavior>
            </i:Interaction.Behaviors>
        </Button>

Made it so much easier to just stumble around into without having to go look up the docs for a change. ☺️

Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :shipit:

@Sergio0694 Sergio0694 merged commit 5a09775 into microsoft:main Nov 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Put everything in a single namespace
2 participants