Silverlight 4.0 Silverlight Focus()然后命令调用=失败?

Silverlight 4.0 Silverlight Focus()然后命令调用=失败?,silverlight-4.0,focus,Silverlight 4.0,Focus,在调用Focus()之后立即调用命令时,我遇到了问题。该命令似乎没有使用我在文本框中输入的正确值。它使用在我更改值之前存在的值(同步问题) p、 s:我只调用btslown.Focus();使我输入的文本框失去焦点 private void TextBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { Dispatcher.BeginInvoke(() =>

在调用Focus()之后立即调用命令时,我遇到了问题。该命令似乎没有使用我在文本框中输入的正确值。它使用在我更改值之前存在的值(同步问题)

p、 s:我只调用btslown.Focus();使我输入的文本框失去焦点

private void TextBox_KeyDown(object sender, KeyEventArgs e)
    { if (e.Key == Key.Enter)
        {
            Dispatcher.BeginInvoke(() => { btnArrow.Focus(); btnArrow.Command.Execute(null); });
            (sender as Control).Focus();
        }}
我唯一能让它工作的方法就是用这样的线(天哪,我知道!)

我的目标是使用好的文本框值调用命令

我也尝试过KeyUp事件。。。我错过什么了吗


非常感谢

假设您的文本框。文本绑定是双向的:

    private void JTextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            // option 1 - pass the value in
            JButton.Command.Execute(JTextBox.Text); 

            // option 2 - force the binding
            JTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            JButton.Command.Execute(null); 
        }
    }
虽然我想听听选项2有什么缺陷

    private void JTextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            // option 1 - pass the value in
            JButton.Command.Execute(JTextBox.Text); 

            // option 2 - force the binding
            JTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            JButton.Command.Execute(null); 
        }
    }