View with ViewModel and Behaviour

Hello,
I have a View which contains the userprofile of the current user. The view contains a viewmodel with a two-way binding to the single attributes like username or email adress. The view also has a behaviour, which validates the input and shows an error, of the input is not valid. Because of the two-way binding, the viewmodel updates the value even if the behavior says the input is wrong. I need to solve that.

My current approach is to use include the behavior in the viewmodel as a attribute. So I can access the attributes of the behavior in the setter of the attributes in the viewmodel. So I cant stop the update to the wrong inputs. But I can not get access the behavior from my viewmodel in the xaml of the view. Is that a way I can do it at all?

My next approach would be to pass the "isValid" attribute of the behavior to the viewmodel. But here again, I don't know how to do it, is it possible at all?

Last approach would be to create a command in the viewmodel, binding it to a new button in the userprofile, using a one-way binding and somehow pass the inputs from the view to the command and updateing the userprofile.

May be here is someone who can help me?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    If your behavior tells an invalid input, why not clear the Entry's Text? After you set the Entry's Text to an empty string, the corresponding view mode's property will be changed too.

Sign In or Register to comment.