views:

15

answers:

0

my context: Entity Framework 4.0 + WCF Ria Data Service + Silverlight 4. Suppose I have entity People from EF, then I created PeopleVM like:

public class PeopleViewModel : ViewModelBase
    {
        public PeopleViewModel(){
       //....
           this._hasChanges = MyDomainContext.HasChanges;
        }

        private People _People;
        public People People
        {
            get { return _People; }
            set
            {
                if (value != this._People)
                {
                    value = this._People;
                    this.RaisePropertyChanged("People");
                }
            }
        }

        private bool _hasChanges;
        public bool HasChanges
        {
            get { return this._hasChanges; }
            set
            {
                if (this._hasChanges != value)
                {
                    this._hasChanges = value;
                    this.RaisePropertyChanged("HasChanges");
                }
            }
        }

        //........

        private RelayCommand _saveCommand = null;
        public RelayCommand SaveCommand
        {
    //.....
        }

        private RelayCommand _cancelCommand = null;
        public RelayCommand CancelCommand
        {
    //.....
        }
   }

in UI xaml, I set binding as:

<TextBox Text="{Binding People.FirstName, Mode=TwoWay}" />
<TextBox Text="{Binding People.LasttName, Mode=TwoWay}" />

Then I set button in UI as:

<Button Content="Save" Command="{Binding SaveCommand}"  IsEnabled="{Binding HasChanges}"/>
<Button Content="Undo" Command="{Binding CancelCommand}" IsEnabled="{Binding HasChanges}"/>

So what I want is:

  1. initially, button should be disabled because there is no data changes.

  2. when user type some in FirstName, LastName textbox, the button should be enabled.

But with above code, even I change firstname, lastname, the button still in disable status.

How to resolve this problem?