private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
{
// Put all the fields in adding mode
e.Field.Mode = DataFieldMode.AddNew;
if (e.PropertyName == "Password")
{
PasswordBox passwordBox = (PasswordBox)e.Field.Content;
this.registrationData.PasswordAccessor = () => passwordBox.Password;
}
else if (e.PropertyName == "PasswordConfirmation")
{
PasswordBox passwordConfirmationBox = (PasswordBox)e.Field.Content;
this.registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
}
else if (e.PropertyName == "UserName")
{
TextBox textBox = (TextBox)e.Field.Content;
textBox.LostFocus += this.UserNameLostFocus;
}
else if (e.PropertyName == "Question")
{
// Create a ComboBox populated with security questions
ComboBox comboBoxWithSecurityQuestions = RegistrationForm.CreateComboBoxWithSecurityQuestions();
// Replace the control
// Note: Since TextBox.Text treats empty text as string.Empty and ComboBox.SelectedItem
// treats an empty selection as null, we need to use a converter on the binding
e.Field.ReplaceTextBox(comboBoxWithSecurityQuestions, ComboBox.SelectedItemProperty, binding => binding.Converter = new TargetNullValueConverter());
}
}