We have setup some Xamarin behavior for not null entry fields etc, this fires when the user makes a change to a field and we then changed the entry border color, red for invalid.
However, we'd also like to reuse this behaviors when a submit button is tapped.
So I need to fire the TextChanged event manually, any ideas how I can do this, now sure if it's possible ?
public class NotEmptyEntryBehaviour : Behavior<Entry>
{
protected override void OnAttachedTo(Entry bindable)
{
bindable.TextChanged += OnEntryTextChanged;
base.OnAttachedTo(bindable);
}
protected override void OnDetachingFrom(Entry bindable)
{
bindable.TextChanged -= OnEntryTextChanged;
base.OnDetachingFrom(bindable);
}
void OnEntryTextChanged(object sender, TextChangedEventArgs args)
{
if (args == null)
return;
var oldString = args.OldTextValue;
var newString = args.NewTextValue;
}
}

If you want an alternative you can use one of the pre-built validation behaviors that comes with Xamarin.CommunityToolkit package, like
TextValidationBehavior(by specifying a Regexp) or any more specific derived ones (exampleNumericValidationBehavior) that may fit your needs or even create a custom one by sub-classing ValidationBehavior.It let you define custom styles for Valid and InValid states, but more important for the question has an async method called
ForceValidate().Also the Flags property could be interesting.
NotEmptyEntryBehaviourseems closer toTextValidationBehaviorwithMinimumLenght=1xaml
Code
Docs
https://learn.microsoft.com/en-us/xamarin/community-toolkit/behaviors/charactersvalidationbehavior
Repo Samples
https://github.com/xamarin/XamarinCommunityToolkit/tree/main/samples/XCT.Sample/Pages/Behaviors
EDIT
If you want to run the validation from the ViewModel you need to bind ForceValidateCommand as explained in this GitHub discussion/question.