seanmet
Topic Author
Posts: 4
Joined: 19 Jun 2024, 10:01

Raising routed event from ViewModel in MVVM

18 Jul 2024, 16:40

Hey, my question is as follows:

I've created a UserControl (lets call it X) that contains a noesis slider as part of it.
The NoesisSlider comes with a routed event named "ValueChanged" that is raised when the value changes.

Im using X UserControl in a different UserControl(Y) that functions as my main user control.
Both of them are implemented with MVVM pattern, so i have a view class and a view model class for both of them.

My question is, how can i catch this slider routed event in Y userControl?
            <!-- Right Slider -->
            <Canvas Width="112.5" Height="662.5" Canvas.Top="0" Canvas.Left="180.5">
                <customControls:cCustomSliderView Icon="2" x:Name="RightSlider" DataContext="{Binding RightSliderViewModel}"/>
                    <b:Interaction.Triggers>
                        <b:EventTrigger EventName="ValueChanged">
                            <b:InvokeCommandAction Command="{Binding SliderValueChangedCommand}"/>
                        </b:EventTrigger>
                    </b:Interaction.Triggers>
The code above sits in the XAML of my main UserControl(Y).
This approach doesnt work, i cant seem to catch the event.
I also tried creating a routed event in my Y UserControl, but then i want it to be bound the the "ValueChanged" event from the slider, and i cant figure out a way to do so, since my only interaction with this event is from the command that sits in the viewmodel.
 
User avatar
jsantos
Site Admin
Posts: 4063
Joined: 20 Jan 2012, 17:18
Contact:

Re: Raising routed event from ViewModel in MVVM

22 Jul 2024, 12:02

Currently, this functionality is not supported. Interaction Triggers only support events that belong to the same class and do not support attached events. Could you please create a ticket regarding this issue?

As a workaround, you can expose new events in your main UserControl (Y) and implement them by registering to the events of the main UserControl (X) in the code

Who is online

Users browsing this forum: Ahrefs [Bot] and 15 guests