This project is read-only.

multibinding raise error

Oct 28, 2013 at 10:00 PM
Edited Oct 28, 2013 at 10:32 PM
first , many thanks for that great effort.
i tried to bind two controls in the form to the same property of the viewmodel ,example
    protected override void OnInitializeBinding()
    {         .
              ViewModel.Bind(textBox1 , t => t.Text, vm => vm.CurrentPathText);
              ViewModel.Bind(label1, t => t.Text, vm => vm.CurrentPathText);
      }
an error exception"An item with the same key has already been added." is fired

The same error is raised if i tried to bind two different properties of the same control (e.g Text, BackColor) to the same
property of viewmodel.
It seems that every property of viewmodel should be bind once.
how to resolve that exceptions.
thanks.

EDIT
I modified MvvmPOC application , and dropped label 7 in the form and add that line of code:

this.ViewModel.Bind(this.label7 , t => t.Text, vm => vm.LastName, false, DataSourceUpdateMode.OnPropertyChanged);

the same error is raised
and debugger stop at line 31, ViewModelExtensions.cs
viewModel.AttachedControls.Add(GetPropertyName(dataMember), control);
Oct 29, 2013 at 2:07 PM
Edited Oct 29, 2013 at 6:04 PM
i found the problem in the AttachedControls of the viewmodel (dictionary) which is used for validation mechanism( as i think)
A quick work around solution, i modified the ExtensionMethod "Bind" by excluding validation
1)setting the default of validation to false
bool autoValidate = false // true
i suggest to be false by default , for binding is used for different properties of the control like BackColr,...

2) commented the the line (temprary until resolved ) :)
//viewModel.AttachedControls.Add(GetPropertyName(dataMember), control); // as