microsoft / XamlBehaviors

This is the official home for UWP XAML Behaviors on GitHub.
MIT License
702 stars 112 forks source link

Event Trigger interaction with CommandBar.SecondaryCommands #55

Closed nigel-sampson closed 8 years ago

nigel-sampson commented 8 years ago

Haven't had a chance to look into the cause yet, but there is a bug where the EventTriggerBehavior is interacting incorrectly with the popup secondary commands menu of a CommandBar.

I've put up a quick sample of the bug, but the basics are that it appears the behavior is attached to the click event every time the menu is opened. Therefore when the button is clicked the accompanying action is invoked as many times as the menu was opened previously.

ScottIsAFool commented 8 years ago

Sounds like the behaviour either isn't detatching properly, or is attaching every time it gets displayed. Out of interest, are we able to try it with another behaviour? Does it do the same thing?

pedrolamas commented 8 years ago

I've tested with a test behavior using this code:

public class TestBehavior : Behavior
{
    protected override void OnAttached()
    {
        base.OnAttached();

        Debug.WriteLine("OnAttached");
    }

    protected override void OnDetaching()
    {
        Debug.WriteLine("OnDetaching");

        base.OnDetaching();
    }
}

I can see the OnDetaching getting called when the menu closes, so I guess this is only related with the EventTriggerBehavior.

pedrolamas commented 8 years ago

You now have a pull request to fix this! :)