예제 #1
0
        /// <summary>
        /// Confirms if the new text value is a valid positive or negative integer, and updates the preview image position if it is.
        /// If the value is invalid, restores it to the preview value.
        /// </summary>
        /// <param name="sender">The source of the event</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void HandY_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            TextBox tbx = tbxHandY;

            if (tbx.Text == string.Empty)
            {
                this.oldTbxHandY = "0";
                tbx.CaretIndex   = 1;
                return;
            }

            e.Handled = !DrawableUtilities.IsNumber(tbx.Text);

            if (e.Handled)
            {
                int index = DrawableUtilities.Clamp(tbx.CaretIndex - 1, 0, tbx.Text.Length - 1);
                tbx.Text       = this.oldTbxHandY;
                tbx.CaretIndex = index;
            }
            else
            {
                this.oldTbxHandY = tbx.Text;

                Thickness t = imgPreview.Margin;
                t.Top             = PREVIEW_MARGIN_TOP - Convert.ToInt32(imgPreview.Height) - (Convert.ToInt32(tbx.Text) * 2);
                imgPreview.Margin = t;
            }
        }