Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            CustomersFinalAction(false);
            CustomersSetAllActions(true);

            firstNameTextBoxBinding.Path  = new PropertyPath("FirstName");
            lastNameTextBoxBinding.Path   = new PropertyPath("LastName");
            CustomerIdTextBoxBinding.Path = new PropertyPath("CustId");

            makeTextBoxBinding.Path  = new PropertyPath("Make");
            colorTextBoxBinding.Path = new PropertyPath("Color");
            carIdTextBoxBinding.Path = new PropertyPath("CarId");

            cmbCustomersBinding.Path = new PropertyPath("FirstName", "LastName");
            cmbInventoryBinding.Path = new PropertyPath("Make", "Color");

            orderscmbCustomers.SetBinding(TextBox.TextProperty, cmbCustomersBinding);
            orderscmbInventory.SetBinding(TextBox.TextProperty, cmbInventoryBinding);

            inventorymakeTextBox.SetBinding(TextBox.TextProperty, makeTextBoxBinding);
            inventorycolorTextBox.SetBinding(TextBox.TextProperty, colorTextBoxBinding);

            CustomersfirstNameTextBox.SetBinding(TextBox.TextProperty, firstNameTextBoxBinding);
            CustomerslastNameTextBox.SetBinding(TextBox.TextProperty, lastNameTextBoxBinding);
        }
Esempio n. 2
0
        private void SetValidationBinding()
        {
            Binding firstNameValidationBinding = new Binding();

            firstNameValidationBinding.Source = new Customer();
            firstNameValidationBinding.Path   = new PropertyPath("FirstName");
            firstNameValidationBinding.NotifyOnValidationError = true;
            firstNameValidationBinding.Mode = BindingMode.TwoWay;
            firstNameValidationBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            //string required (cant be empty)
            firstNameValidationBinding.ValidationRules.Add(new StringNotEmpty());
            CustomersfirstNameTextBox.SetBinding(TextBox.TextProperty, firstNameValidationBinding);
            Binding lastNameValidationBinding = new Binding();

            lastNameValidationBinding.Source = new Customer();
            lastNameValidationBinding.Path   = new PropertyPath("LastName");
            lastNameValidationBinding.NotifyOnValidationError = true;
            lastNameValidationBinding.Mode = BindingMode.TwoWay;
            lastNameValidationBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            //string min length validator (min 3 characters)
            lastNameValidationBinding.ValidationRules.Add(new StringMinLengthValidator());
            CustomerslastNameTextBox.SetBinding(TextBox.TextProperty, lastNameValidationBinding); //setare binding nou
        }
Esempio n. 3
0
        /// <summary>
        /// this function
        /// </summary>
        /// <param name="set">true Setbindings, false Clearbindings and set temporary values to textboxes</param>
        private void CustomersTextboxBindings(bool set)
        {
            if (set)
            {
                //Setbindings between grid and textboxes
                CustomersfirstNameTextBox.SetBinding(TextBox.TextProperty, firstNameTextBoxBinding);
                CustomerslastNameTextBox.SetBinding(TextBox.TextProperty, lastNameTextBoxBinding);
            }
            else
            {
                //save temporarly textboxes values
                string tempFirstName = CustomersfirstNameTextBox.Text;
                string tempLastName  = CustomerslastNameTextBox.Text;


                //grid and textboxes bindings are cleared
                BindingOperations.ClearBinding(CustomersfirstNameTextBox, TextBox.TextProperty);
                BindingOperations.ClearBinding(CustomerslastNameTextBox, TextBox.TextProperty);

                //Set back temporary values to textboxes, as bindigs cleared
                CustomersfirstNameTextBox.Text = tempFirstName;
                CustomerslastNameTextBox.Text  = tempLastName;
            }
        }