开发者

numericUpDown ValueChanged after MouseLeftButtonDown

I have 2 controls on a form. One numericUpDown (from the Silverlight Toolkit) and a simple Rectangle.

On the MouseLeftButtonDown of the Rectangle I popup a MessageBox with the numericUpDown value.

If I use the arrows to开发者_如何学Python change the value of the numericUpDown, everyting is fine. But if I edit the value manually (with the keyboard) and immediately click on the Rectangle it shows the previous value of the numericUpDown. If I click a sencond time on the rectangle it will show the new value.

The numericUpDown.ValueChanged event is raised after the Rectangle.MouseLeftButtonDown event.

Is that a Silverlight bug? Anybody knows a workaround for that?

(btw I cannot change my Rectangle controls or events)


As workaround I propose you to create your own control like:

public class MyNumericUpDown : NumericUpDown
    {
        private TextBox _textBox;
        public void Sync()
        {
            ApplyValue(_textBox.Text);
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _textBox = (TextBox)GetTemplateChild("Text");
        }
    }

Now you can use method Sync to syncronize display text with control Value property. You can call method from XAML declaratively or in code behind. In your case:

private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            myNumericUpDown.Sync();
            MessageBox.Show(myNumericUpDown.Value.ToString());
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜