niknowj
niknowj

Reputation: 1037

how to implement control events in wpf using MVVM?

I have a slider control in view i need to call the ValueChanged event of slider and update one property in model based on that. how i can implement this using MVVM pattern. where I have to write the ValueChanged event? how i can connect ValueChanged event code with view?

Upvotes: 0

Views: 1522

Answers (1)

blindmeis
blindmeis

Reputation: 22445

i just take the answer from here cause i use it in my projects too:

You should use an EventTrigger in combination with InvokeCommandAction from the Windows.Interactivity namespace. Here is an example:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 

<i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectionChanged">
        <i:InvokeCommandAction Command="{Binding SelectedItemChangedCommand}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

Upvotes: 1

Related Questions