Ejemplo n.º 1
0
        /// <summary>
        /// Handles the Spin event of the ButtonSpinner control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.Windows.Controls.SpinEventArgs"/> instance containing the event data.</param>
        private void ButtonSpinner_Spin(object sender, Microsoft.Windows.Controls.SpinEventArgs e)
        {
            ButtonSpinner spinner = (ButtonSpinner)sender;
            TextBox       txtBox  = (TextBox)spinner.Content;
            Binding       binding = txtBox.GetBindingExpression(TextBox.TextProperty).ParentBinding;

            int value = String.IsNullOrEmpty(txtBox.Text) ? 0 : Convert.ToInt32(txtBox.Text);

            if (e.Direction == Microsoft.Windows.Controls.SpinDirection.Increase)
            {
                value++;
            }
            else
            {
                value--;
            }
            if (value <= 0)
            {
                value = 1;
            }
            typeof(Settings).GetProperty(binding.Path.Path).SetValue(Settings.Default, Convert.ToUInt32(value), null);
        }
        private void ButtonSpinner_Spin(object sender, Microsoft.Windows.Controls.SpinEventArgs e)
        {
            ButtonSpinner spinner = (ButtonSpinner)sender;
            TextBox       txtBox  = (TextBox)spinner.Content;

            try
            {
                int value = String.IsNullOrEmpty(txtBox.Text) ? 0 : Convert.ToInt32(txtBox.Text);
                if (e.Direction == Microsoft.Windows.Controls.SpinDirection.Increase)
                {
                    value++;
                }
                else
                {
                    value--;
                }
                txtBox.Text = value.ToString();
            }
            catch
            {
                txtBox.Text = "0";
            }
        }
 /// <summary>
 /// Can be called by a spinner event to adjust data prior to data processing.
 /// </summary>
 /// <param name="sender">The ButtonSpinner that was pressed</param>
 /// <param name="e">The data returned by the ButtonSpinner's Spin event</param>
 public void SpinnerPressed(object sender, SpinEventArgs e)
 {
     foreach (SpinnerData d in _spinnerList)
     {
         if (d.Spinner == sender as ButtonSpinner)
         {
             if (e.Direction == SpinDirection.Increase)
             {
                 d.Value++;
                 if (d.Value >= d.Maximum)
                 {
                     d.Value = d.Maximum;
                     d.Spinner.ValidSpinDirection = ValidSpinDirections.Decrease;
                 }
                 else
                 {
                     d.Spinner.ValidSpinDirection = ValidSpinDirections.Increase | ValidSpinDirections.Decrease;
                 }
             } 
             else
             {
                 d.Value--;
                 if (d.Value <= d.Minimum)
                 {
                     d.Value = d.Minimum;
                     d.Spinner.ValidSpinDirection = ValidSpinDirections.Increase;
                 }
                 else
                 {
                     d.Spinner.ValidSpinDirection = ValidSpinDirections.Increase | ValidSpinDirections.Decrease;
                 }
             }
             return;
         }
     }
 }