currently I don't know how to solve my problem. I am writing an app with xamarin.forms.
I have a view which contains the userprofile of the user. For example there is a entry with the username. The field is binded in the twoway mode to the viewmodel:
<Entry x:Name="givennameSurname" Text="{Binding FullName, Mode=TwoWay}" />
The whole userprofile contains some fields which are validated with a behavior:
<behaviors:TelNumBehavior x:Name="NumValidatorUser" IsValid="{Binding Source={x:Reference root}, Path=BindingContext.UserTelNumBehavior, Mode=TwoWay }"></behaviors:TelNumBehavior>
The isValid property is also binded to the viewmodel.
What I want to achieve? I want, that if one of the behaviors validate the input to false, that the userprofile can not be updated.
So I wanted to create a command on a button. The button has an canExecute method: this method checks the booleans in the viewmodel if they all are true or false. If true, I want to force a refresh of the data of viewmodel from the view. I use that canExecute also to prevent unwanted changes, if the UI is in the state, that some input is wrong:
public string FullName
{
get => profile.GivenName;
set
{
if (CanSave())
{
profile.GivenName = value;
OnPropertyChanged();
}
}
}
What is the problem? I change an input with a behavior, so that the behavior says the input is wrong. Then I edit the username. Then I change the input of the wrong-behavior to true. Now the input of the username does not refresh in the viewmodel. I want to refresh it with the command, but I don't know how to force a refresh from the view to the viewmodel.