-
How to access the control instance from the view model |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The general approach is not to do this: MVVM strong discourages interacting directly with the view from the VM. If you really need to, you can access the How exactly you go about it depends on what problem you're solving. For dynamically adding lines to a canvas for example, you would normally have the VM expose a |
Beta Was this translation helpful? Give feedback.
The general approach is not to do this: MVVM strong discourages interacting directly with the view from the VM. If you really need to, you can access the
View
property on the ViewModel, and cast it to your view type.How exactly you go about it depends on what problem you're solving. For dynamically adding lines to a canvas for example, you would normally have the VM expose a
BindableCollection
containing a list of objects describing your lines (e.g. start and end point). Then you might be able to bind to that in your XAML, or you might need to bind it to an attached behaviour or read it in the codebehind.