S
S
Space Purr2019-04-18 22:48:44
WPF
Space Purr, 2019-04-18 22:48:44

How to handle an event within MVVM via Interactions.Triggers in a linked library?

Hello.
And so, what's the problem.
I can handle the event via Interaction.Triggers like this

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"

<i:Interaction.Triggers>
     <i:EventTrigger EventName="Drop">
           <ei:CallMethodAction
               MethodName="DropFilesToCollection"
               TargetObject="{Binding}"/>
      </i:EventTrigger>
</i:Interaction.Triggers>

In the ViewModel it will look like this
public void DropFilesToCollection(object sender, DragEventArgs e)
        {
            var files = (string[])e.Data.GetData(DataFormats.FileDrop);
            OpenFileMaster.Add(files);
        }

And everything works great.
Now consider the second situation.
I downloaded the library for inserting animations into Image via NuGet and connected it in this way . This package has an event that catches the moment the animation ends, which, like all other events, can be added to Main (where InitializeComponent is) and, I checked, the event works. However, if I want to process it in the ViewModel, within MVVM, in this way
xmlns:gif="http://wpfanimatedgif.codeplex.com"
gif:ImageBehavior.AnimationCompleted=""
<i:Interaction.Triggers>
     <i:EventTrigger EventName="gif:ImageBehavior.AnimationCompleted">
           <ei:CallMethodAction
               MethodName="Image_AnimationCompleted"
               TargetObject="{Binding}"/>
      </i:EventTrigger>
</i:Interaction.Triggers>

then nothing works.
I would like to know how to work with the events of connected libraries within MVVM.
I suspect that it is not necessary to write everything through MVVM, but it just so happens that the ViewModel often has a lot of objects that I need to work with and that should be involved in events, and since I started doing this seriously, I want to know the answers)
Thank you .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Foggy Finder, 2019-04-19
@SpacePurr

Write your own trigger to account for attached events. As, for example, done here:
https://sergecalderara.wordpress.com/2012/08/23/ho...
or here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question