# 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**

```C#
    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](https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callermembernameattribute\(v=vs.110\).aspx) 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**

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

## See Also

* [Delegate Command](https://www.telerik.com/winui/documentation/common/mvvm-helpers/delegatecommand)
* [BindableCollection](https://www.telerik.com/winui/documentation/common/mvvm-helpers/bindablecollection)
