Fellow forum dwellers, my rusty programing skills stem from the old day of using events and are unused within the MVVM environment. I have a very simple problem to solve.
I have a DataForm all bound to a database via a view and RIA services.
The form is very simple, it has a checkbox, and 3 text boxes. It was fairly easy to wire all up even with my non-existent MVVM skills.
However I encountered a problem, I would like to have the 3rd box generate the text automatically. More precisely, if the checkbox is checked then I want the 3rd box to be populated with the values in the other two boxes multiplied by each other.
Naturally in the old event way this would be quite easy, but I am completely stumped on how to do it within my view.
Any help would be appreciated.
5 Answers, 1 is accepted
- Bind your checkbox to a bool property in your viewmodel. Whenever that value changes to true, perform the calculation and update a property in the vm that holds the result.
- The textbox that displays the result must bind to the result propety in the vm.
- You must also bind the other two textboxes to their own int properties in the viewmodel. These must use twoway bindings.
- When any of the two "multiplier" properties change, you must check if the bool property is true. If it is, perform the calculation and update the result property.
All 4 elements are already bound to an entity object within my ViewModel.
The problem i am having is with step 4.
"When any of the two properties change ... " how do i know they change?
There is no event in my ViewModel.
The Entity Obejct i am binding the controls to is:
public
OwlRecord NewOwlRecord
{
get
{
return
_newOwlRecord; }
set
{
if
(value != _newOwlRecord)
{
_newOwlRecord = value;
}
}
}
So basically, instead of listening to events you listen to the changes in the property setters, either in your viewmodel or your entities.
And i pass the changes back to the entity when required.