Blend 4中经常看到一个输入框,里面有值还有单位,当获取到焦点的时候,就只有值了,修改完值之后,失去焦点,单位又加上了。

class myTextbox : TextBox
    {
        private int _timeValue=100;

        public int TimeValue
        {
            get { return _timeValue; }
            set { _timeValue = value; }
        }

        public myTextbox()
        {
            this.Text = TimeValue.ToString()+"";
            GotFocus += myTextbox_GotFocus;
            LostFocus += myTextbox_LostFocus;
        }

        void myTextbox_LostFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            TimeValue = Convert.ToInt32(this.Text.ToString());
            this.Text = TimeValue.ToString() + "";
        }

        void myTextbox_GotFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Text = TimeValue.ToString();
        }
    }

这样就实现了...

 

相关文章:

  • 2021-08-05
  • 2021-05-29
  • 2022-12-23
  • 2022-01-02
  • 2021-09-23
  • 2022-02-14
  • 2021-10-17
  • 2021-06-17
猜你喜欢
  • 2022-12-23
  • 2021-09-29
  • 2021-06-28
  • 2022-01-19
  • 2022-12-23
  • 2021-07-18
  • 2021-10-29
相关资源
相似解决方案