V
V
Viktor Zorin2021-02-20 16:35:39
.NET
Viktor Zorin, 2021-02-20 16:35:39

How to correctly handle an event in WPF?

We need to handle the KeyDown event on a Slider in WPF. As far as I understand, the use of events is discouraged in MVVM. How to implement our plans with the help of commands and what would be the best solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
P40b0s, 2021-02-21
@FutureAnge1

They are just used a little differently. If you are not yet using a framework for MVVM, then I advise you to start right away with it. For example Prism:
add

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

and process:
<Button Content="нажать" >
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="KeyDown">
            <i:InvokeCommandAction Command="{Binding KeyDownCommand}"   CommandParameter="param"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question