Question

I'm designing UI in WPF for logic circuit simulator. I want my application to support various behaviors depending on current operation mode like selection mode (rubberband selection), component placing mode, wiring mode, interaction mode etc. I thought about using state pattern in my ViewModel and encapsulating the behaviors in states corresponding to operation modes.

My trouble is reflecting this changes in the View. I want each mode to subscribe to different mouse events (selection is mouse down, mouse move, mouse up; placing is mouse enter, mouse move, mouse leave). Can I encapsulate this in generic behaviors and then somehow switch behaviors at runtime? Should I use attached properties for it? Or maybe custom control? What's the MVVM way of doing this?

Était-ce utile?

La solution

Are the different behaviours linked to mouse events only and the XAML of UserControl is always the same?

If the answer is yes then you can implements a single behaviour attached to all mouse events you want to manage in all scenarios and store the current scenario inside a variable of the UserControl.

Doing so, your custom behaviour can decide to call or not to call a particular ICommand, basing on the value of the variable of the UserControl that indicates the current scenario.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top