views:

54

answers:

1

Hi all,

I'm using the mvvm-light toolkit in my windows phone 7 application.

I have in my view :

<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}"  />

My view model is :

    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);
        }
    }
}

In the emulator, when I type value in the textbox, and I click the button, I can see that I'm going first in the relaycommand lambda expression and with a breakpoint I see that MyValue is null. Then, the breakpoint in the setter of MyValue is reached, and the correct value goes in MyValue.

What am I doing wrong ? Of course, I would like that the setter can be reached before the RelayCommand...

Thanks in advance for any help.

A: 

It is possible that you have hit the TextBox DataBinding issue with the TextChanged event. This is a recognized problem in Silverlight 3, see this thread discussing this issue and the workaround. A neat solution is perhaps to use behaviors as discussed in this article.

HTH, indyfromoz

indyfromoz
thanks for your answer. you are talking about SL 3, but I'm using SL4, this changes something ?
Tim
Note that Windows Phone 7 Silverlight is Silverlight 3 with some bits from Silverlight 4. Have a look at this post - http://www.silverlighthack.com/post/2010/03/16/Silverlight-for-Windows-Phone-7-is-NOT-the-same-full-Silverlight-3-RTM.aspx, there are other posts discussing the Silverlight version on the WP7
indyfromoz