Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
28407
How to prevent changing the ActiveRecord when bound to a property in your ViewModel
posted

HI,

You can do this by tracking the previous record in the viewmodel

Here is the binding for the XamDataGrid’s ActiveRecord property.

<igDP:XamDataGrid ExecutingCommand="xgrid1_ExecutingCommand" ActiveRecord="{Binding ActiveRecord, Mode=TwoWay}"
                          RecordActivated="xgrid1_RecordActivated"
                          Name="xgrid1" DataSource="{Binding People}">

Here is the property on the ViewModel:

Record activerecord;
public Record ActiveRecord
{
    get { return activerecord; }
    set {
        if (changeactive)
        {
            activerecord = value;
            prevrecord = activerecord;
            NotifyPropertyChanged("ActiveRecord");
        }
        else
        {
            activerecord = prevrecord;
        // throw new Exception("cant change record");
        }
       
    }
         
}

Record prevrecord;
public Record PrevRecord
{
    get { return prevrecord; }
    set { prevrecord = value;
    NotifyPropertyChanged("PrevRecord");}
}

 When you run the sample, you can't change the XamDataGrid's ActiveRecord until you check the EnableActivation Checkbox.

 

 

Sincerely,
 Matt
Developer Support Engineer

WpfApplication255.zip
Parents
No Data
Reply
  • 270
    posted

    You want to go neater (MVVM) friendly way you can you MVVMLights EventToCommand Trigger to bind to Command in your View Model

    In that CheckActiveRecordChangeCommand  (in your ViewModel). you can decide to Cancel moving to another record.

    You will need to listen for RecordDeactivating event when using EventToCommand.

     

Children
No Data