locked
Behaviors don't work on flyouts RRS feed

  • Question

  • Hi,

    in my app I'm trying to using a behavior in a button flyout to invoke a command on flyout Closed event:

    <Button>
    	<Button.Flyout>                                                            
    		<Flyout>
    			<Interactivity:Interaction.Behaviors>
    				<Core:EventTriggerBehavior EventName="Closed">
    					<Core:InvokeCommandAction Command="{Binding MyCommand}" />
    				</Core:EventTriggerBehavior>
    			</Interactivity:Interaction.Behaviors>			
    		</Flyout>
    	</Button.Flyout>
    </Button>

    When I run the app I get this execption:

    Cannot add instance of type Microsoft.Xaml.Interactions.Core.EventTriggerBehavior to a collection of type Microsoft.Xaml.Interactivity.BehaviorCollection.


    Where is the problem? Behaviors cannot be used in Flyouts?

    Monday, January 13, 2014 5:26 AM

All replies

  • Does it work if you change the eventname to Tapped?

    I found this which shows that it works:

    http://windowspak.com/using-a-behavior-to-open-attached-flyouts-in-windows-8-1-store-apps/


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, January 14, 2014 4:09 PM
    Moderator
  • In the sample you provided the behavior is attached to the image and not to the flyout.
    I'd like to add a behavior to the flyout in order to invoke a command when the flyout is closed.

    I think there is a problem with behaviors attached to flyouts.

    Wednesday, January 15, 2014 4:22 AM
  • Do you mind sharing a project with me?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, January 17, 2014 1:34 PM
    Moderator
  • Saturday, January 18, 2014 4:46 AM
  • it's not the flyout. I had the same problem in the Datatemplate of a listview. I moved it from the datatemplate to the Listview itself, and ik was allright.
    Tuesday, January 21, 2014 3:18 PM
  • Is it possible that behaviors work only with elements that inherit from Control class?

    Popup inherits from FrameworkElement and beahviors don't work.
    Button inherits from Control and behaviors work.



    Friday, January 24, 2014 3:21 PM
  • I've been working on this and what you're saying appears to be correct.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, January 24, 2014 4:18 PM
    Moderator
  • Hi,

    also DatePicker doesn't support behaviors, I get the same exception:

    Cannot add instance of type Microsoft.Xaml.Interactions.Core.EventTriggerBehavior to a collection of type Microsoft.Xaml.Interactivity.BehaviorCollection

    DatePicker however inherits from Control.

    Thursday, March 20, 2014 4:56 AM