WPF: How to attach mouse events to a viewmodel?

后端 未结 6 1998
南笙
南笙 2021-02-04 19:47

I am trying to use the MVVM pattern for the first time. So I have an ItemsControl filled with my viewmodel objects, displayed using DataTemplate\'s; th

6条回答
  •  温柔的废话
    2021-02-04 20:30

    The ViewModel should be disconnected from the GUI, so it doesn't know anything about controls or mouseclicks.

    Two options:

    • Call a command in the the ViewModel, as suggested by Thomas
    • Bind the position of the thumb to a property in the ViewModel, then when the control moves around WPF will update the position values in the ViewModel.

提交回复
热议问题