I have a Xamarin Forms content page with the following structure and code behind and I am trying to update the UI Entry Text by updating the ViewModel property inside the Appearing event handler (I am trying to simulate OnLoad). The issue is that the Entry text is not updated.
XAML:
<StackLayout Padding="20">
<Entry Placeholder="Username" x:Name="usernameEntry" Text="{Binding Username, Mode=TwoWay}"></Entry>
<Entry Placeholder="Password" x:Name="passwordEntry" Text="{Binding Password}" />
<Button x:Name="registerButton" Text="Register" />
</StackLayout>
C#:
public partial class UserCredentialsPage : ContentPage
{
public UserCredentialsPage()
{
InitializeComponent();
this.BindingContext = this.ViewModel;
this.Appearing += UserCredentialsPage_Appearing;
}
public BaseViewModel ViewModel { get; } = new UserCredentialsViewModel();
void UserCredentialsPage_Appearing (object sender, EventArgs e)
{
var vm = (UserCredentialsViewModel)ViewModel;
vm.Username = "test";
}
}
Thanks!