Windows phone 7 使用MVVM Light toolkit时,在绑定之前过早引发[WP7][MVVM Light toolkit]按钮命令

Windows phone 7 使用MVVM Light toolkit时,在绑定之前过早引发[WP7][MVVM Light toolkit]按钮命令,windows-phone-7,mvvm-light,Windows Phone 7,Mvvm Light,我正在windows phone 7应用程序中使用mvvm light toolkit 我认为: <TextBox Height="78" HorizontalAlignment="Left" Margin="108,33,0,0" VerticalAlignment="Top" Width="313" Text="{Binding MyValue, Mode=TwoWay}" /> <Button Content="Go" Height="78" HorizontalAlig

我正在windows phone 7应用程序中使用mvvm light toolkit

我认为:

<TextBox Height="78" HorizontalAlignment="Left" Margin="108,33,0,0" VerticalAlignment="Top" Width="313" Text="{Binding MyValue, Mode=TwoWay}" />
<Button Content="Go" Height="78" HorizontalAlignment="Left" Margin="127,252,0,0" Name="button1" VerticalAlignment="Top" Width="213" cmd:ButtonBaseExtensions.Command="{Binding DoCommand}"  />
在emulator中,当我在文本框中键入值并单击按钮时,我可以看到我首先进入relaycommand lambda表达式并带有一个断点 我看到MyValue为null。然后,到达MyValue的setter中的断点,正确的值进入MyValue

我做错了什么?当然,我希望能在中继命令之前联系到二传手


提前感谢您的帮助。

您可能遇到了TextChanged事件的TextBox数据绑定问题。这是Silverlight 3和解决方案中公认的问题。一个简洁的解决方案可能是使用中讨论的行为


谢谢你的回答。你说的是SL3,但我用的是SL4,这改变了一些东西?请注意,WindowsPhone7Silverlight是Silverlight3,带有Silverlight4中的一些位。看看这篇文章-,还有其他文章讨论WP7上的Silverlight版本
    public class MainPageViewModel : ViewModelBase
    {
        public ICommand DoCommand { get; internal set; }
    public MainPageViewModel()
    {
        DoCommand = new RelayCommand(() =>
            {
                DoSomethingWith(MyValue);
            }, () => true);

    }

    private const string MyValuePropertyName = "MyValue";
    private string _myValue;
    public string MyValue
    {
        get { return _myValue; }
        set
        {
            if (_myValue == value)
                return;
            _myValue = value;
            RaisePropertyChanged(MyValuePropertyName);
        }
    }
}