1

I have a basic registration page when the user register her data, I save an object of this data in a static field of the Settings static class , so I can fill the common fields with other registration pages, like first_name, last_name, email...etc. so the user doesn't have to re-fill them again.

the very specific case I have is, one of these common pages is the basic registration page itself (with some fields excluded). first that's how the common fields look like:

<Entry Text="{Binding RegistrationData.first_name, Mode=TwoWay}"  Grid.Row="1" Grid.Column="0" Placeholder="{Resx:TranslateExtension Text=lbFirstName}"/>
<Entry Text="{Binding RegistrationData.last_name, Mode=TwoWay}"  Grid.Row="2" Grid.Column="0" Placeholder="{Resx:TranslateExtension Text=lbLastName}"/>
<Entry Text="{Binding RegistrationData.email, Mode=TwoWay}" Keyboard="Email"  Grid.Row="3" Grid.Column="0" Placeholder="{Resx:TranslateExtension Text=lbEmail}"/>

apparently the model implements INotifyPropertyChanged.

in the constructor of the Register page:

public Register(int userType) //when I call this constructor the registration page represent some sub-registration pages
{
    InitializeComponent();
    var oRegistrationViewModel = (RegistrationViewModel)BindingContext;
    if (Settings.UserData != null)
    {     
        oRegistrationViewModel.RegistrationData = Settings.UserData;
        BindingContext = oRegistrationViewModel;
    }
}

but it doesn't work, when I reset the BindingContext the data is not bound to the fields.

I set the Settings.UserData in the OnRegister method of the RegisterCommand in the view-model, when called from the basic page (with default constructor)

I'm using GalaSoft.MvvmLight I set the BindingContext in XAML:

BindingContext="{Binding Register, Source={StaticResource Locator}}"

the Locator is a key of the ViewModelLocator, in the constructor:

SimpleIoc.Default.Register<RegistrationViewModel>();

and this property:

public RegistrationViewModel Register
{
    get
    {
        return SimpleIoc.Default.GetInstance<RegistrationViewModel>();
    }
}

I need to know when the BindingContext is set with binding in XAML, Is this happen when calling InitializeComponent(), when I called it after resetting the BindingContext the data still not shown.

Julian
  • 5,290
  • 1
  • 17
  • 40
mshwf
  • 7,009
  • 12
  • 59
  • 133
  • `OnBindingContextChanged` event might help you, as described [in this answer](https://stackoverflow.com/a/37872231/199364). – ToolmakerSteve May 18 '18 at 08:16

0 Answers0