I have a WPF Window, and in that window I have a grid.
I use M-V-VM model and I want to add a TextBox to the grid dynamically in code(in viewmodel)
How can I get access to the grid?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use Supervising Controller pattern.
Reading:
Example implementation for CaliburnMicro MVVM framework is shown here (will work same for all other frameworks – or you can do it by hand if you are doing MVVM by yourself):
http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-tutorial-talk-to-view
Example:
1) Define interface
IViewin whichViewModel(VM) will talk toViewwith the required method(s)2) Inherit code behind
Viewfrom yourIViewand implementIView.AddTextboxToGrid()method3) Add a property of type
IViewto yourVM4) Set
Viewproperty onVMto an instance ofViewasIViewe.g. in code behind:
or in Caliburn you can use IScreen.OnViewAttached override method)
5) In your
VMcallIView.AddTextboxToGrid()