Replies: 1 comment 3 replies
-
To be honest, casting the DataContext (or ActionTarget) to the ViewModel's type is more safe than using If you want to imitate what |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to have access to viewmodel's methods from code-behind. Something aka {s:Action }.
I know I can use the datacontext, but I'd have to cast that to the name of the VM. (would crash, if name changed for some reason).
As example, I'd like to catch right mouse clicks on some gui element and the VM should display some info on that. Binding the event using eg. {s:Action DoRightMouse} (in xaml) would give the VM access to the MouseButtonsEventArgs, telling about the GUI internal widgets like TextBlocks and so on. The VM is not really interested in the internals of the View, but rather needs some logical information on what to display. Therefore I'd like to call a code-behind method where I could assemble and parameterize all info of interest to the VM. Then, it would be nice, if I could call into the current ActionTarget (wherever that is) to have my info displayed.
Is that possible?
Thxs (also for the excellent software gem, Stylet)
Alfons
Beta Was this translation helpful? Give feedback.
All reactions