locked
[UWP]Will there be a Behavior SDK to support EventTriggerBehavior, InvokeCommandAction?

    Question

  • I am using MVVM techniques to build a UWP app.  Previously I used the Behavior SDK to get the Microsoft.Xaml.Interactivity namespace, and used EventTriggerBehavior and InvokeCommandAction to bind to a command in my ViewModel.  Is it likely we'll see similar support in UWP?
    Tuesday, June 02, 2015 5:48 PM

Answers

  • >>Is it likely we'll see similar support in UWP?

    Windows 8.1 class libraries can be referenced and used as is in a Windows 10 Universal App.

    So you should be able to add a reference to the very same Behavior SDK that you are using in a Windows 8.1 project and use the types in the Microsoft.Xaml.Interactivity namespace in a Windows Universal App.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by David Cater Wednesday, June 03, 2015 1:16 AM
    Tuesday, June 02, 2015 8:40 PM
  • x:Bind is supported for events, For example

    <GridView x:Name="mygrid" ItemsSource="{Binding Cars}" SelectionChanged="{x:Bind Model.SelectionChanged}">

    In this case SelectionChanged should have a signature that matches the event, or no parameters. It doesn't give you the ability to bind a command parameter, but if using the method signature, it will be passed the sender object.

    • Marked as answer by David Cater Friday, July 31, 2015 2:42 AM
    Thursday, July 30, 2015 10:48 PM

All replies

  • >>Is it likely we'll see similar support in UWP?

    Windows 8.1 class libraries can be referenced and used as is in a Windows 10 Universal App.

    So you should be able to add a reference to the very same Behavior SDK that you are using in a Windows 8.1 project and use the types in the Microsoft.Xaml.Interactivity namespace in a Windows Universal App.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by David Cater Wednesday, June 03, 2015 1:16 AM
    Tuesday, June 02, 2015 8:40 PM
  • Thanks; I'll give that a shot.  
    Tuesday, June 02, 2015 8:45 PM
  • That worked like a champ.  Here's specifically what I did:

    • In a sample Windows 8.1 Windows Store (WinRT) project where I had installed the Behaviors SDK, I checked the properties of the BehaviorsXamlSDKManaged assembly and got the path to the root (C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\BehaviorsXamlSDKManaged\12.0\ for me).
    • In that folder, I drilled down until I found the actual assemblies (C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\BehaviorsXamlSDKManaged\12.0\References\CommonConfiguration\Neutral)
    • I copied Microsoft.Xaml.Interactions.dll and Microsoft.Xaml.Interactivity.dll to a common folder accessible to all of my assemblies that might need those ($myroot$\Assemblies\Win8DLLs).
    • In my UWP universal class library that contains my View layer I added a manual reference to those DLLs.
    • In my XAML I now have code similar to the following:

    <Page       
    ...
        xmlns:interact="using:Microsoft.Xaml.Interactivity"
        xmlns:interactcore="using:Microsoft.Xaml.Interactions.Core"
        >
    ...
        <GridView x:Name="mygrid" ItemsSource="{Binding Cars}">
            <interact:Interaction.Behaviors>
                <interactcore:EventTriggerBehavior EventName="SelectionChanged">
                    <interactcore:InvokeCommandAction
                        Command="{Binding SelectCarCommand}}"
                        CommandParameter="{Binding ElementName=mygrid, Path=SelectedItem}"/>
                </interactcore:EventTriggerBehavior>
            </interact:Interaction.Behaviors>
        </GridView>

    Thanks very much, Magnus!



    • Edited by David Cater Wednesday, June 03, 2015 1:25 AM Wording
    Wednesday, June 03, 2015 1:24 AM
  • Note that it appears you can add a reference to the Behaviors SDK in the Add Reference dialog for UWP apps now (VS2015 RTM). It adds a reference to:

    C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\BehaviorsXamlSDKManaged\12.0\

    And the identity is:

    BehaviorsXamlSDKManaged, Version=12.0

    Thursday, July 30, 2015 7:42 PM
  • x:Bind is supported for events, For example

    <GridView x:Name="mygrid" ItemsSource="{Binding Cars}" SelectionChanged="{x:Bind Model.SelectionChanged}">

    In this case SelectionChanged should have a signature that matches the event, or no parameters. It doesn't give you the ability to bind a command parameter, but if using the method signature, it will be passed the sender object.

    • Marked as answer by David Cater Friday, July 31, 2015 2:42 AM
    Thursday, July 30, 2015 10:48 PM
  • Excellent. That works well. In my case I need to know the selected item, which I'll have to get from the GridView.  And I don't want to refer to the GridView in the ViewModel, so I'm binding directly to a method in the Page's code-behind, which figures out the selected item and then passes it to the ViewModel.  But I like that better than having to go through the InvokeCommandAction.
    Friday, July 31, 2015 2:44 AM
  • Even though it works when you add the reference to Behavior SDK (XAML) my concern is that it appears a Warning sign. It tells you to verify the SDK's compatibility.
    I have not experienced any issue for the moment.
    Does any of you have experienced some weird behavior or something?
    Thursday, August 20, 2015 11:45 AM
  • So far it seems to be working fine for me.
    Thursday, August 20, 2015 11:50 AM
  • It seems that .NET native doesn't support it. Can you confirm that? Build your project with release with Compile  with .NET native tool chain checked in in Build tab in project properties and run app.

    DataTrigger works correctly, try to use EventToCommand property.

    • Edited by MistyK Sunday, August 30, 2015 8:46 PM
    Sunday, August 30, 2015 8:44 PM
  • Apparently there is good news.

    Read this blog: XAML Behaviors, open source and on UWP.

    To install via the NuGet Package Console, run the following command for managed projects:

    PM> Install-Package Microsoft.Xaml.Behaviors.Uwp.Managed

    For native:

    PM> Install-Package Microsoft.Xaml.Behaviors.Uwp.Native


    Shimmy

    Tuesday, February 09, 2016 3:59 AM