I am developing a windows 8.1 app using VS 2013 and MVVM Light.
The following code shows the behavior in a flyout within an appbar:
<AppBarButton.Flyout>
<Flyout x:Name="FlyoutCalculator"
Placement="Top"
FlyoutPresenterStyle="{StaticResource FlyoutPresenterBaseStyle}">
<uc:Calculator ApplyCommand="{Binding CancelCommand}"
CancelCommand="{Binding CancelCommand}"
Available="{Binding AvailableCounter, Mode=OneWay}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"/>
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Opening">
<core:InvokeCommandAction Command="{Binding ShowCurrentCostsCommand}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Flyout>
</AppBarButton.Flyout>
Unfortunately I get an exception while compiling the app:
WinRT-Informationen: Cannot add instance of type
Microsoft.Xaml.Interactions.Core.EventTriggerBehaviorto a collection of typeMicrosoft.Xaml.Interactivity.BehaviorCollection
Other Behaviors in the View do work, does someone know a solution to this?
I do not have a solution but: I'm not using Flyouts in my Windows 8.1 App, I'm using a UserControl on which I have added a
EventTriggerBehavioras you did. And I get exactly the same Errormessage from VisualStudio at runtime. As I am using aRoutedEventHandlerthis could cause the Problem as you useas the Trigger for the Behavior. But that is just an idea of what is the problem.
For me I have found an answer:
I have changed the Type of my
RoutedEventHandlerto be just a normalEventHandler. And the Method inside the CodeBehind which triggers theRoutedEventHandleris invoked with only the sender, because I dont know how to convertRoutedEventArgsintoEventArgs, but as long as I dont need the EventArgs it's not a problem.You could also make a workaround by creating a UserControl with a Flyout Control and make the Opening Event public to the Page where you use it. Then you can add the
EventTriggerBehaviorto the UserControl and connect it to your customOpeningEvent and you should get the expected behavior.