MVVM : Assign ItemSource in View's Code Behind
-
Hello To All, I am new to MVVM with Silverlight. MyTestView --> View (Button, Grid) MyTestViewModel --> ViewModel (WCF Service Methods) In my button call I have assigned the DataContext. I have to fill grid with the data that have been returned from the service call in the same click event in the View's code behind. Any help regarding this will be greatly appreciated.. Thanks in adv...
-
Hello To All, I am new to MVVM with Silverlight. MyTestView --> View (Button, Grid) MyTestViewModel --> ViewModel (WCF Service Methods) In my button call I have assigned the DataContext. I have to fill grid with the data that have been returned from the service call in the same click event in the View's code behind. Any help regarding this will be greatly appreciated.. Thanks in adv...
As in your other post, you are misunderstanding MVVM. All your code belongs in the ViewModel, not in the code behind (there are a few exceptions). You should not be assigning DataContext in button handlers. It should be set once using something like the view locator pattern. Everything that the View gets from the ViewModel is done with data binding, not code in the code behind.
-
As in your other post, you are misunderstanding MVVM. All your code belongs in the ViewModel, not in the code behind (there are a few exceptions). You should not be assigning DataContext in button handlers. It should be set once using something like the view locator pattern. Everything that the View gets from the ViewModel is done with data binding, not code in the code behind.
Hi.. Thanks for the reply. But I have situation for getting search criteria from the page and perform the operation in the button click event based on passing the search criteria to the view model. So, How can I get view's control value in the viewmodel? Can u pls give a hint about how to overcome such type of situations? Thanks..
-
Hi.. Thanks for the reply. But I have situation for getting search criteria from the page and perform the operation in the button click event based on passing the search criteria to the view model. So, How can I get view's control value in the viewmodel? Can u pls give a hint about how to overcome such type of situations? Thanks..
The search criteria should be bound to a property on the VM. You then have the data in the VM, responding to the event (click the search or the key up/down) need to be handled.
Never underestimate the power of human stupidity RAH
-
Hello To All, I am new to MVVM with Silverlight. MyTestView --> View (Button, Grid) MyTestViewModel --> ViewModel (WCF Service Methods) In my button call I have assigned the DataContext. I have to fill grid with the data that have been returned from the service call in the same click event in the View's code behind. Any help regarding this will be greatly appreciated.. Thanks in adv...
Set the view's datacontext to the view model. You could then apply commands to handle the button command click in the view model.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.