New to Telerik UI for WinUI? Download free 30-day trial

ViewModelBase

The ViewModelBase abstract class is designed to serve as a base class for any view model that needs to raise the PropertyChanged event.

ViewModelBase implements the INotifyPropertyChanged interface. This means that you can directly inherit the class in your view models instead of implementing the interface for each model separately.

Example 1: Custom ViewModel that inherits ViewModelBase

using Telerik.Windows.Controls; 
public class MyViewModel : Telerik.Core.ViewModelBase 
{ 
    private MyItemInfo selectedItem; 
    private ObservableCollection<MyItemInfo> items; 
 
    public MyItemInfo SelectedItem 
    { 
        get { return this.selectedItem; } 
        set 
        { 
            if (value != this.selectedItem) 
            { 
                this.selectedItem = value; 
                this.OnPropertyChanged(() => this.SelectedItem); 
            } 
        } 
    } 
 
    public ObservableCollection<MyItemInfo> Items 
    { 
        get 
        { 
            return this.items; 
        } 
        set 
        { 
            this.items = value; 
            this.OnPropertyChanged("Items"); 
        } 
    } 
} 
As shown in Example 1, when explicitly specifying the changed property, there are few overloads for the OnPropertyChanged method. The OnPropertyChanged method supports also the CallerMemberName attribute which means that you can call the method without providing the property's name.

Example 2: Using the OnPropertyChanged overload with the CallerMemberName attribute

public MyItemInfo SelectedItem 
{ 
    get { return this.selectedItem; } 
    set 
    { 
        if (value != this.selectedItem) 
        { 
            this.selectedItem = value; 
            this.OnPropertyChanged(); 
        } 
    } 
} 

See Also

In this article
Not finding the help you need?