/// <summary>
        /// Handles the situation where the <see cref="DataForm"/> auto-generates a field.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event args.</param>
        private void OnDataFormAutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "BoolProperty":
                e.Cancel = true;
                break;

            case "IntProperty":
            {
                ComboBox comboBox = new ComboBox();
                comboBox.ItemsSource = new IntCollection();
                comboBox.SetBinding(ComboBox.SelectedItemProperty, new Binding("IntProperty")
                    {
                        Mode = BindingMode.TwoWay
                    });
                e.Field = new DataField()
                {
                    Content = comboBox
                };
            }

            break;
            }
        }
        /// <summary>
        /// Wire up the Password and PasswordConfirmation Accessors as the fields get generated.
        /// </summary>
        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());
            }
        }
示例#3
0
        protected override void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
        {
            // normally change this condition to check it is one of your complex types
            // or that it is not a basic type.
            if (e.Field.IsReadOnly == true)
            {
                e.Field.DescriptionViewerVisibility = Visibility.Visible;
            }

            if (e.PropertyType.BaseType == typeof(UserModelEntity))
            {
                var control = new SuperDataForm();

                control.CommandButtonsVisibility = DataFormCommandButtonsVisibility.None;
                control.IsReadOnly = false;
                control.AutoCommit = false;

                Controls.Add(control);
                Binding binding = new Binding(e.PropertyName);
                binding.Mode = BindingMode.TwoWay;
                binding.ValidatesOnExceptions   = true;
                binding.NotifyOnValidationError = false;
                control.SetBinding(DataForm.CurrentItemProperty, binding);
                e.Field.IsReadOnly = false;
                e.Field.Content    = control;
            }
        }
示例#4
0
 private void dataForm1_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "IDProdotto")
     {
         e.Cancel = true;
     }
 }
示例#5
0
 private void meetingDataForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName.In("Start", "End"))
     {
         e.Field.ReplaceDatePicker(new TextBox(), TextBox.TextProperty);
     }
 }
示例#6
0
 static void Form_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "Extensions" || e.PropertyName == "Error" || e.PropertyName == "HasErrors")
     {
         e.Cancel = true;
     }
 }
        /// <summary>
        /// Wire up the Password and PasswordConfirmation accessors as the fields get generated.
        /// Also bind the Question field to a ComboBox full of security questions, and handle the LostFocus event for the UserName TextBox.
        /// </summary>
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            // Put all the fields in adding mode
            e.Field.Mode = DataFieldMode.AddNew;

            if (e.PropertyName == "UserName")
            {
                this.userNameTextBox            = (TextBox)e.Field.Content;
                this.userNameTextBox.LostFocus += this.UserNameLostFocus;
            }
            else if (e.PropertyName == "Password")
            {
                PasswordBox passwordBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
                this.registrationData.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                PasswordBox passwordConfirmationBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordConfirmationBox, PasswordBox.PasswordProperty);
                this.registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
            }
            else if (e.PropertyName == "Question")
            {
                ComboBox questionComboBox = new ComboBox();
                questionComboBox.ItemsSource = RegistrationForm.GetSecurityQuestions();
                e.Field.ReplaceTextBox(questionComboBox, ComboBox.SelectedItemProperty, binding => binding.Converter = new TargetNullValueConverter());
            }
        }
示例#8
0
 private void companyForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "Logo")
     {
         FileUpload fileUploader = new FileUpload();
         e.Field.ReplaceTextBox(fileUploader, FileUpload.UploadedFileProperty);
     }
 }
示例#9
0
 /// <summary>
 /// Handles <see cref="DataForm.AutoGeneratingField"/> to provide the PasswordAccessor.
 /// </summary>
 private void LoginForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "Password")
     {
         PasswordBox passwordBox = (PasswordBox)e.Field.Content;
         this.loginInfo.PasswordAccessor = () => passwordBox.Password;
     }
 }
示例#10
0
 /// <summary>
 ///     Handles <see cref="DataForm.AutoGeneratingField"/>. Adds the necessary event listeners
 ///     so that the OK button will only be enabled when both username and password are filled
 /// </summary>
 private void LoginForm_OnAutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "UserName")
     {
         ((TextBox)e.Field.Content).TextChanged += EnableOrDisableOKButton;
     }
     else if (e.PropertyName == "Password")
     {
         ((PasswordBox)e.Field.Content).PasswordChanged += EnableOrDisableOKButton;
     }
 }
示例#11
0
        private static void DataForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs eventArgs)
        {
            var generator = new UIHintGenerator(eventArgs.PropertyName, eventArgs.PropertyType, (System.Windows.Controls.DataForm)sender);
            var control   = generator.Generate();

            if (control != null)
            {
                control = generator.Bind(control, generator.UIHintAttribute, generator.PropInfo);
                eventArgs.Field.Content    = control;
                eventArgs.Field.IsReadOnly = false;
            }
        }
示例#12
0
 private void editForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "MemberID" || e.PropertyName == "BookID" || e.PropertyName == "Category" || e.PropertyName == "CategoryID" || e.PropertyName == "BookOfDays")
     {
         e.Cancel = true;
     }
     if (e.PropertyName == "Description")
     {
         TextBox textDesc = (TextBox)e.Field.Content;
         textDesc.AcceptsReturn = true;
     }
 }
 /// <summary>
 /// Handles <see cref="DataForm.AutoGeneratingField"/> to provide the PasswordAccessor.
 /// </summary>
 private void LoginForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "UserName")
     {
         this.userNameTextBox = (TextBox)e.Field.Content;
     }
     else if (e.PropertyName == "Password")
     {
         PasswordBox passwordBox = new PasswordBox();
         e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
         this.loginInfo.PasswordAccessor = () => passwordBox.Password;
     }
 }
示例#14
0
        /// <summary>
        ///     Extends <see cref="DataForm.OnAutoGeneratingField" /> by replacing <see cref="TextBox"/>es with <see cref="PasswordBox"/>es
        ///     whenever applicable
        /// </summary>
        protected override void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
        {
            // Get metadata about the property being defined
            PropertyInfo propertyInfo = this.CurrentItem.GetType().GetProperty(e.PropertyName);

            // Do the password field replacement if that is the case
            if (e.Field.Content is TextBox && this.IsPasswordProperty(propertyInfo))
            {
                e.Field.ReplaceTextBox(new PasswordBox(), PasswordBox.PasswordProperty);
            }

            // Keep this newly generated field accessible through the Fields property
            this.fields[e.PropertyName] = e.Field;

            // Call base implementation (which will call other event listeners)
            base.OnAutoGeneratingField(e);
        }
示例#15
0
        /// <summary>
        /// Wire up the Password and PasswordConfirmation accessors as the fields get generated.
        /// Also bind the Question field to a ComboBox full of security questions, and handle the LostFocus event for the UserName TextBox.
        /// </summary>
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            // Put all the fields in adding mode
            e.Field.Mode = DataFieldMode.AddNew;

            var registrationData = DataContext as RegistrationData;

            if (e.PropertyName == "UserName")
            {
                this.userNameTextBox = (TextBox)e.Field.Content;
                this.userNameTextBox.LostFocus += this.UserNameLostFocus;
            }
            else if (e.PropertyName == "Password")
            {
                PasswordBox passwordBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
                registrationData.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                PasswordBox passwordConfirmationBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordConfirmationBox, PasswordBox.PasswordProperty);
                registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
            }
            else if (e.PropertyName == "Foundry")
            {
                this.foundryCombobox = new ComboBox();
                foundryCombobox.ItemsSource = Foundries;
                e.Field.ReplaceTextBox(foundryCombobox, ComboBox.SelectedItemProperty);
                foundryCombobox.SelectionChanged += this.foundryComboboxSelectionChanged;
            }
            else if (e.PropertyName == "Role")
            {
                roleCombobox = new ComboBox();
                roleCombobox.ItemsSource = Roles;
                e.Field.ReplaceTextBox(roleCombobox, ComboBox.SelectedItemProperty);
                roleCombobox.SelectionChanged += this.roleComboboxSelectionChanged;
            }

            else if (e.PropertyName == "CustomerCompany")
            {
                this.customerCombobox = new ComboBox();
                e.Field.ReplaceTextBox(customerCombobox, ComboBox.SelectedItemProperty);
            }
        }
 private void OnFormAutoGenerateField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyType.IsEnum)
     {
         var combbox = new ComboBox();
         combbox.ItemsSource   = EnumHelper.GetNames(e.PropertyType);
         combbox.SelectedIndex = 0;
         combbox.SetBinding(Selector.SelectedItemProperty, new Binding
         {
             Path                  = new PropertyPath(e.PropertyName),
             Mode                  = BindingMode.TwoWay,
             Converter             = enumConverter,
             ValidatesOnDataErrors = true
         });
         e.Field.IsReadOnly = e.PropertyName.Equals("DocType", StringComparison.CurrentCulture);
         e.Field.Content    = combbox;
     }
 }
示例#17
0
        /// <summary>
        /// Handles <see cref="DataForm.AutoGeneratingField"/> to provide the PasswordAccessor.
        /// </summary>
        private void ChangePasswordForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
        {
            PasswordBox passwordBox = new PasswordBox();

            e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
            if (e.PropertyName == "Password")
            {
                this.changePasswordInfo.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "OldPassword")
            {
                this.oldPasswordTextBox = (PasswordBox)e.Field.Content;
                this.changePasswordInfo.OldPasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                this.changePasswordInfo.PasswordConfirmationAccessor = () => passwordBox.Password;
            }

            //both password boxes need to be replaced
        }
示例#18
0
 private void OnDataFormAutoGenerateField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyType == typeof(SystemUser) || e.PropertyType == typeof(DateTime))
     {
         e.Cancel = true;
     }
     if (e.PropertyType.IsEnum)
     {
         var combbox = new ComboBox();
         combbox.ItemsSource   = EnumHelper.GetNames(e.PropertyType);
         combbox.SelectedIndex = 0;
         combbox.SetBinding(Selector.SelectedItemProperty, new Binding
         {
             Path                  = new PropertyPath(e.PropertyName),
             Mode                  = BindingMode.TwoWay,
             Converter             = enumConverter,
             ValidatesOnDataErrors = true
         });
         e.Field.Content = combbox;
     }
 }
示例#19
0
        /// <summary>
        ///     Adds some additional behaviors to some of the DataForm's fields
        /// </summary>
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            if (e.PropertyName == "Password")
            {
                PasswordBox passwordBox = (PasswordBox)e.Field.Content;

                passwordBox.PasswordChanged += (sender, eventArgs) =>
                {
                    // If the password is invalid, the entity property doesn't get updated.
                    // Thus, we keep a separate password copy (the ActualPassword property)
                    // that is guaranteed to match what the user typed
                    ((RegistrationData)this.registerForm.CurrentItem).ActualPassword = ((PasswordBox)sender).Password;
                };

                passwordBox.LostFocus += (sender, eventArgs) =>
                {
                    // Prevent this from having any effect after a submission
                    if (this.registrationData.EntityState == EntityState.Unmodified)
                    {
                        return;
                    }

                    // If there is something typed on the password confirmation box
                    // then we need to re-validate it
                    if (!String.IsNullOrEmpty(((PasswordBox)this.registerForm.Fields["PasswordConfirmation"].Content).Password))
                    {
                        this.registerForm.Fields["PasswordConfirmation"].Validate();
                    }
                };
            }
            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());
            }
            else if (e.PropertyName == "UserName")
            {
                // Auto-fill FriendlyName if there is not already something in there
                TextBox userNameTextBox = (TextBox)e.Field.Content;

                userNameTextBox.LostFocus += (sender, eventArgs) =>
                {
                    // Prevent this from having any effect after a submission
                    if (this.registrationData.EntityState == EntityState.Unmodified)
                    {
                        return;
                    }

                    TextBox friendlyNameTextBox = (TextBox)this.registerForm.Fields["FriendlyName"].Content;

                    if (string.IsNullOrEmpty(friendlyNameTextBox.Text))
                    {
                        friendlyNameTextBox.Text = userNameTextBox.Text;
                    }
                };
            }
        }
        /// <summary>
        /// Handles the situation where the <see cref="DataForm"/> auto-generates a field.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event args.</param>
        private void OnDataFormAutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "BoolProperty":
                    e.Cancel = true;
                    break;

                case "IntProperty":
                    {
                        ComboBox comboBox = new ComboBox();
                        comboBox.ItemsSource = new IntCollection();
                        comboBox.SetBinding(ComboBox.SelectedItemProperty, new Binding("IntProperty") { Mode = BindingMode.TwoWay });
                        e.Field = new DataField() { Content = comboBox };
                    }

                    break;
            }
        }