[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)

Passing Data Between ViewModels (ISupportParameter)

The ViewModelBase class implements the ISupportParameter interface. This interface provides the ISupportParameter.Parameter property, that you can use to pass initial data to View Models.

Note

The POCO mechanism does not generate the ISupportParameter interface implementation automatically, but you can implement this interface in your POCO View Model manually.

The following code demonstrates how to set the ISupportParameter.Parameter property in code behind, when a Detail View Model is created from the Main View Model.

When the ISupportParameter.Parameter property is set, the ViewModelBase.OnParameterChanged virtual method is invoked. You can override the ViewModelBase.OnParameterChanged virtual method to process passed data.

Expanded Passing Data Between Loosely Coupled Main and Detail View Model

You can implement passing data from a Main to a Detail View Model when these View Models are loosely coupled, i.e., when View Models do not know about each other. In this case, you should set the ViewModelExtensions.Parameter attached property in XAML. The diagram below illustrates how it works.

Here, the Main View contains an instance of a Detail View. The Views' DataContexts are the MainViewModel and DetailViewModel respectively. To pass data from the Main View/Main ViewModel to the Detail ViewModel, assign the data to the ViewModelExtensions.Parameter attached property on the Detail View instance.

How it works. When the Parameter attached property is set on the Detail View, the ViewModelExtensions class identifies whether the View's DataContext is a ViewModelBase descendant. To be more precise, the ViewModelExtensions class identifies whether the DataContext is an object that implements the ISupportParameter interface. If so, the ViewModelExtensions class passes the new Parameter value to the Detail View's ViewModel: the new value is assigned to the ViewModel's ISupportParameter.Parameter private property.

When the Parameter private property is changed, the Detail ViewModel calls its OnParameterChanged protected method. You can manually override the OnParameterChanged protected method to access and use the new parameter value.

Expanded Example

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