Ticket T944883
Visible to All Users

MVVM - How to update ViewModel properties once a user changes values in corresponding bound TextEditors

created 4 years ago (modified 4 years ago)

[DevExpress Support Team: CLONED FROM T943854: Masks do not work starting with v.20.2]

The reason for the bindings is to give the ViewModel a chance to react to changes to data. For example, in an editor's EditValue:

C#
// ViewModel public virtual string FirstName { get; set; } public void OnFirstNameChanged() { this.RaiseCanExecuteChanged(x => x.Accept()); }

Is there an alternative method that does not require the use of individual bindings in the View?

Answers approved by DevExpress Support

created 4 years ago

Hello,

Do I understand it correctly that you wish to update your ViewModel properties immediately after a user changes values in the corresponding TextEditors? If so, I recommend you add the DataSourceUpdateMode parameter to your DataBinding and set it to OnPropertyChanged in the following way:

C#
this.txtFirstName.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.personSource, "FirstName", true, DataSourceUpdateMode.OnPropertyChanged)); this.txtLastName.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.personSource, "LastName", true, DataSourceUpdateMode.OnPropertyChanged));

Does this solution resolve the issue? If not, it would be of great help if you send us a sample illustrating the issue. We will research it and do our best to find a suitable solution quickly.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.