2

In our current C# project, we use the MVVM light framework and its EventToCommand feature to bind events to commands (as also mentioned in this SO thread). We use it for example like this:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="GotFocus">
        <cmd:EventToCommand CommandParameter="{Binding SelectedItem, ElementName=SelectTree}"
                            Command="{Binding Path=SelectTreeGotFocusCommand, Mode=OneWay}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

My question is: What is the easiest way to achieve the same behaviour (i.e., EventToCommand, not limited to GotFocus) without using System.Windows.Interactivity?

To avoid the XY problem, here is some background:

  • We are developing an addon for an already existing main application, on which we do not have any influence. Our addon is served as a dll which is used by this main application.
  • So far, we used XAML code as given above (i.e., using System.Windows.Interactivity and EventToCommand). However, the last release of the main application contains an old version of System.Windows.Interactivity (so far, it was not included at all) which doesn't support this.
  • This means that using the old Interactivity.dll will cause our addon to be non-functional. However, overwriting the dll with the new version we need will cause issues with parts of the main application.
  • I read about using two different versions of the same dll in a project (for example here) but this seems to be quite involved. Since there are only a few places we use this construction, I thought that replacing it with code not using Interactivity.dll might be easier.
Community
  • 1
  • 1
boothby81
  • 265
  • 3
  • 6

1 Answers1

1

If you switch to the Microsoft.Xaml.Behaviors.Wpf nuget package and change your namespace declarations to

xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

you can use the InvokeCommandAction like so:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="GotFocus"}">
        <i:InvokeCommandAction Command="..." CommandParameter="..."/>
    </i:EventTrigger>
</i:Interaction.Triggers>
IngoB
  • 2,552
  • 1
  • 20
  • 35