[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Collapse]MVVM Framework
  [Collapse]View Models
    BindableBase
    ViewModelBase
    POCO ViewModels
    Interaction of ViewModels
    Passing Data Between ViewModels (ISupportParameter)
    ViewModel relationships (ISupportParentViewModel)
  [Expand]Commands
  [Expand]Behaviors
  [Expand]Services
  [Expand]DXBinding
  [Expand]MIF
   Converters
   ViewLocator
   Messenger
   Data Annotation Attributes
   LayoutTreeHelper
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

BindableBase

The BindableBase class implements the INotifyPropertyChanged interface and provides the API to declare bindable property with minimum coding.

Expanded Bindable Properties

To declare bindable properties, do the following:

  • inherit your ViewModel from the BindableBase class;
  • use the GetValue and SetValue methods in property getters and setters.

+The BindableBase class exposes the GetValue and SetValue overloads that use the CallerMemberNameAttribute (see System.Runtime.CompilerServices.CallerMemberNameAttribute). You do not have to pass property name to these methods' parameter. This simplifies the bindable property declaration:

Note

The CallerMemberNameAttribute (see System.Runtime.CompilerServices.CallerMemberNameAttribute) is available in .NET Framework 4.5 and above.

The BindableBase in .NET Framework 4.0 section describes how to use the BindableBase View Model in .NET 4.0.

Property values are stored in an internal dictionary:

  • the GetValue method uses this dictionary to get a property value;
  • the SetValue method uses the property name as a key to store a property value in the dictionary.

The SetValue method returns True or False values that indicate whether a property has been changed. If you set the same value to the property, the SetValue method returns False and change notifications are not sent.

Expanded Run Custom Code When Property Value Changed

The SetValue method has overloads that take a callback method as a parameter. This callback is invoked after a property value has been changed.

Expanded Manually Raise INotifyPropertyChanged.PropertyChanged

If you need to raise the INotifyPropertyChanged.PropertyChanged event for a specific property, use the RaisePropertyChanged/RaisePropertiesChanged method.

Expanded Using Properties With Backing Fields

An application's performance can decrease when a property is frequently accessed or updated because property values are stored in the Dictionary. To improve the application's performance, store property values in backing fields.

Expanded BindableBase in .NET Framework 4.0

Bindable Properties

Use the GetProperty and SetProperty methods to implement bindable properties.

The first parameter of the GetProperty and SetProperty methods is a lambda expression that returns the property used to identify the target property name. The property names are internally obtained with the static BindableBase.GetPropertyName<T> method.

Run Custom Code When Property Value Changed

The SetProperty method returns True or False values that indicate whether a property was changed. If you set the property to the same value, the SetProperty method returns False and changing notifications are not sent. The SetProperty method has overloads that take a callback method as a parameter. This callback is invoked after the field has been changed.

Manually Raise INotifyPropertyChanged.PropertyChanged

If you need to raise the INotifyPropertyChanged.PropertyChanged event for a specific property, use the RaisePropertyChanged/RaisePropertiesChanged method.

Using Properties With Backing Fields

An application performance can decrease when a property is frequently updated (due to the calculation of property names from lambda expressions and storing property values in the Dictionary). To accommodate these scenarios, use storage variables for properties and calculate property names once from the static constructor using the BindableBase.GetPropertyName<T> method.

Is this topic helpful?​​​​​​​