Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1235
DataBinding in MVVM pattern
posted

Hi 

I'm using the following syntax on the xam side
                                            <ig:XamColorPicker SelectedColor="{Binding Path=OperatorColor, UpdateSourceTrigger=PropertyChanged}"/

and I have a ViewModel that exposes the following property:

 private static PropertyChangedEventArgs operatorColorChangeArgs = ObservableHelper.CreateArgs<OperatorsViewModel>(x => x.OperatorColor);

        private Color? operatorColor;
        [CanBeDirty]
        public Color? OperatorColor
        {
            get { return operatorColor; }
            set
            {
                operatorColor = value;
                NotifyPropertyChanged(operatorColorChangeArgs);
            }
        }


very much like all the other properties in the model ie the LastName property:

   private static PropertyChangedEventArgs lastNameAddressChangeArgs = ObservableHelper.CreateArgs<OperatorsViewModel>(x => x.LastName);

        private String lastName;
        [CanBeDirty]
        public String LastName
        {
            get { return lastName; }
            set
            {
                lastName = value;
                NotifyPropertyChanged(lastNameAddressChangeArgs);
            }
        }
Now as for the OperatorColor it works the first time I load the data and I positively set  the xamColorPicker selectedcolor property and each operator gets its color correctly.
Nonetheless when the user picks another color the change doesn't fire to the bound property on the ViewModel class while all the other properties do so. I don't have a clue.
Do you?
Thanks
 Roberto Dalmonte

Parents
No Data
Reply
  • 66
    posted

    I encountered the same problem and it seems that de binding is default oneway, if you set the binding mode to twoway it works.

    <ig:XamColorPicker SelectedColor="{Binding Path=OperatorColor, Mode=TwoWay}"


    You don't even have to use the UpdateSourceTrigger then.

    Hope this helps.

    Eelke van Helvoort

Children
No Data