Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

MVVM Two way binding on Entry inside the Appearing event handler

$
0
0

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!


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>