This project is read-only.

Is there a way to fire a Behavior in code?

Feb 18, 2013 at 5:51 PM
Edited Feb 18, 2013 at 5:52 PM
Problem is, you cannot have a behavior attached to a Button in an AppBar, so I need to be able to "fire" it in the code behind in the Click event of a button. Snippet below of attached behavior. In fact the entire AppBar loses all click and hover effects. It's almost like having this one behavior in an AppBar just kills the appbar.
<Button x:Name="RateContentButton" AutomationProperties.Name="Rate Content" Style="{StaticResource SolidStarAppBarButtonStyle}">
    <Behaviors:ShowRateCourseBehavior Event="Tapped"/>
Feb 24, 2013 at 8:18 AM
Sorry, I can't see much without seeing some more code. A behavior doesn't have a built-in concept of firing. It fires when your behavior's code is ready to perform an action - if it has a concept of doing that. You can add a behavior by calling Interaction.GetBehaviors(RateContentButton).Add(new ShowRateCourseBehavior()...) IIRC.
Feb 24, 2013 at 6:12 PM
Because of this:

If you add a WinRTBehavior to an AppBar button it doesn't work, and all click/effects for the entire AppBar stop working. Thus I wondered if I could just use the AppBar Buttons Click event, and fire a behavior in the back.
Feb 24, 2013 at 9:28 PM
Sorry, I'd say the same thing - WinRTBehaviors is a different library than WinRT XAML Toolkit. I have no idea what ShowRateCourseBehavior is, but I bet you can find the source code for it and debug it to see why it might not work. I'd ask the question in the discussion forum of the project where you found ShowRateCourseBehavior or perhaps Stack Overflow.