# Passing Data Between ViewModels (ISupportParameter) | WPF Controls | DevExpress Documentation

The [ViewModelBase](/WPF/17351/mvvm-framework/viewmodels/viewmodelbase) class implements the [ISupportParameter](/CoreLibraries/DevExpress.Mvvm.ISupportParameter) interface. This interface provides the [Parameter](/CoreLibraries/DevExpress.Mvvm.ISupportParameter.Parameter) property, that you can use to pass initial data to View Models.

Note

The [POCO](/WPF/17352/mvvm-framework/viewmodels/runtime-generated-poco-viewmodels) mechanism does not generate the [ISupportParameter](/CoreLibraries/DevExpress.Mvvm.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](/CoreLibraries/DevExpress.Mvvm.ISupportParameter.Parameter) property in code-behind when a Detail View Model is created from the Main View Model.

- C#
- VB.NET

<section id="tabpanel_CernuTFozW_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code class="lang-csharp">public class MainViewModel : ViewModelBase {
    public DetailViewModel DetailViewModel { get; private set; }
    public MainViewModel() {
        DetailViewModel = new DetailViewModel();
        ((ISupportParameter)DetailViewModel).Parameter = &quot;Document 1&quot;;
    }
}
</code></pre></section>
<section id="tabpanel_CernuTFozW_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code class="lang-vb">Public Class MainViewModel
    Inherits ViewModelBase
    Dim _DetailViewModel As DetailViewModel
    Public ReadOnly Property DetailViewModel As DetailViewModel
        Get
            Return _DetailViewModel
        End Get
    End Property
    Public Sub New()
        _DetailViewModel = New DetailViewModel()
        DirectCast(_DetailViewModel, ISupportParameter).Parameter = &quot;Document 1&quot;
    End Sub
End Class
</code></pre></section>

When the [Parameter](/CoreLibraries/DevExpress.Mvvm.ISupportParameter.Parameter) property is set, the **ViewModelBase.OnParameterChanged** virtual method is invoked. You can override the **ViewModelBase.OnParameterChanged** virtual method to process passed data.

- C#
- VB.NET

<section id="tabpanel_CernuTFozW-1_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code class="lang-csharp">public class DetailViewModel : ViewModelBase {
    protected override void OnParameterChanged(object parameter) {
        base.OnParameterChanged(parameter);
        if(IsInDesignMode) {
            //...
        } else {
            //...
        }
    }
}
</code></pre></section>
<section id="tabpanel_CernuTFozW-1_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code class="lang-vb">Public Class DetailViewModel
    Inherits ViewModelBase
    Protected Overrides Sub OnParameterChanged(parameter As Object)
        MyBase.OnParameterChanged(parameter)
        If IsInDesignMode Then
            &#39;...
        Else
            &#39;...
        End If
    End Sub
End Class
</code></pre></section>

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

![ISupportParameter-scheme](/WPF/images/isupportparameter-scheme19443.png)

Here, the Main View contains an instance of a Detail View. The Views’ **DataContext**s 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.

- XAML

<section id="tabpanel_CernuTFozW-2_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.MainView&quot; ...
    xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
    xmlns:View=&quot;clr-namespace:Example.View&quot;
    xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;&gt;
    &lt;UserControl.DataContext&gt;
        &lt;ViewModel:MainViewModel/&gt;
    &lt;/UserControl.DataContext&gt;
    &lt;Grid x:Name=&quot;LayoutRoot&quot;&gt;
        ...
        &lt;!-- It is necessary to use the ElementName binding mode, 
        because the DetailView&#39;s DataContext is a DetailViewModel object. 
        That is why the following regular binding cannot be used 
        in this case: dxmvvm:ViewModelExtensions.Parameter=&quot;{Binding}&quot;
        Instead, use one of the following constructions:--&gt;
        &lt;View:DetailView dxmvvm:ViewModelExtensions.Parameter=&quot;{Binding DataContext, ElementName=LayoutRoot}&quot;/&gt;
        &lt;ContentControl&gt;
            &lt;ContentControl.ContentTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;View:DetailView dxmvvm:ViewModelExtensions.Parameter=&quot;{Binding DataContext, Source={x:Reference LayoutRoot}}&quot;/&gt;
                &lt;/DataTemplate&gt;
            &lt;/ContentControl.ContentTemplate&gt;
        &lt;/ContentControl&gt;
        ...
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>

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

## Example

[View Example](https://github.com/DevExpress-Examples/wpf-mvvm-framework-pass-data-between-view-models-through-the-isupportparameter-interface)

- MainWindow.xaml
- MainViewModel.cs
- ChildViewModelBase.cs
- ChildView1.xaml
- MainView.xaml
- ChildView2.xaml
- ChildPOCOViewModel.cs

<section id="tabpanel_kbLwPqqL7i_tabid-MainWindow-xaml" role="tabpanel" data-tab="tabid-MainWindow-xaml">
<pre><code class="lang-xaml">&lt;Window x:Class=&quot;Example.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:View=&quot;clr-namespace:Example.View&quot;
        Title=&quot;MainWindow&quot; Height=&quot;600&quot; Width=&quot;800&quot;&gt;
    &lt;Grid&gt;
        &lt;View:MainView/&gt;
    &lt;/Grid&gt;
&lt;/Window&gt; 
</code></pre></section>
<section id="tabpanel_kbLwPqqL7i_tabid-csharpMainViewModel-cs" role="tabpanel" data-tab="tabid-csharpMainViewModel-cs" aria-hidden="true" hidden="hidden">
<pre><code class="lang-csharp">namespace Example.ViewModel {
    public class MainViewModel {
        public virtual string Parameter1 { get; set; }
        public virtual string Parameter2 { get; set; }
        public void ChangeParameter1() {
            counter1++;
            Parameter1 = &quot;Parameter #&quot; + counter1.ToString();
        }
        public void ChangeParameter2() {
            counter2++;
            Parameter2 = &quot;Parameter #&quot; + counter2.ToString();
        }

        int counter1 = 0;
        int counter2 = 0;
    }
}
</code></pre></section>
<section id="tabpanel_kbLwPqqL7i_tabid-csharpChildViewModelBase-cs" role="tabpanel" data-tab="tabid-csharpChildViewModelBase-cs" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;}" class="lang-csharp">using DevExpress.Mvvm;

namespace Example.ViewModel {
    public class ChildViewModelBase : ViewModelBase {
        IMessageBoxService MessageBoxService { get { return GetService&lt;IMessageBoxService&gt;(ServiceSearchMode.PreferParents); } }
        protected override void OnParameterChanged(object parameter) {
            base.OnParameterChanged(parameter);
            if(parameter is string)
                MessageBoxService.Show(&quot;ChildViewModelBase: Parameter = &quot; + (string)parameter);
        }
    }
}
</code></pre></section>
<section id="tabpanel_kbLwPqqL7i_tabid-xamlChildView1-xaml" role="tabpanel" data-tab="tabid-xamlChildView1-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.ChildView1&quot;
             xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
             xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
             mc:Ignorable=&quot;d&quot; 
             d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;300&quot;&gt;
    &lt;UserControl.DataContext&gt;
        &lt;ViewModel:ChildViewModelBase/&gt;
    &lt;/UserControl.DataContext&gt;
    &lt;Grid&gt;
        &lt;TextBlock Text=&quot;This View has a ViewModel derived from the ViewModelBase class&quot; TextWrapping=&quot;Wrap&quot;/&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_kbLwPqqL7i_tabid-xamlMainView-xaml" role="tabpanel" data-tab="tabid-xamlMainView-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.MainView&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
    xmlns:View=&quot;clr-namespace:Example.View&quot;
    xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
    xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot; d:DesignHeight=&quot;500&quot; d:DesignWidth=&quot;600&quot;
    DataContext=&quot;{dxmvvm:ViewModelSource ViewModel:MainViewModel}&quot;&gt;

    &lt;dxmvvm:Interaction.Behaviors&gt;
        &lt;dx:DXMessageBoxService/&gt;
    &lt;/dxmvvm:Interaction.Behaviors&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;StackPanel Orientation=&quot;Vertical&quot;&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;Button Content=&quot;Change Parameter1&quot; Command=&quot;{Binding ChangeParameter1Command}&quot;/&gt;
                &lt;Button Content=&quot;Change Parameter2&quot; Command=&quot;{Binding ChangeParameter2Command}&quot;/&gt;
            &lt;/StackPanel&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;Border BorderThickness=&quot;1&quot; BorderBrush=&quot;Black&quot; Margin=&quot;10&quot; Width=&quot;300&quot; Height=&quot;100&quot;&gt;
                    &lt;View:ChildView1 dxmvvm:ViewModelExtensions.ParentViewModel=&quot;{Binding DataContext, ElementName=LayoutRoot}&quot;
                                     dxmvvm:ViewModelExtensions.Parameter=&quot;{Binding DataContext.Parameter1, ElementName=LayoutRoot}&quot;/&gt;
                &lt;/Border&gt;
            &lt;/StackPanel&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;Border BorderThickness=&quot;1&quot; BorderBrush=&quot;Black&quot; Margin=&quot;10&quot; Width=&quot;300&quot; Height=&quot;100&quot;&gt;
                    &lt;View:ChildView2 dxmvvm:ViewModelExtensions.ParentViewModel=&quot;{Binding DataContext, ElementName=LayoutRoot}&quot;
                                     dxmvvm:ViewModelExtensions.Parameter=&quot;{Binding DataContext.Parameter2, ElementName=LayoutRoot}&quot;/&gt;
                &lt;/Border&gt;
            &lt;/StackPanel&gt;
        &lt;/StackPanel&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_kbLwPqqL7i_tabid-xamlChildView2-xaml" role="tabpanel" data-tab="tabid-xamlChildView2-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.ChildView2&quot;
             xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
             xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
             mc:Ignorable=&quot;d&quot; 
             d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;300&quot;
             DataContext=&quot;{dxmvvm:ViewModelSource ViewModel:ChildPOCOViewModel}&quot;&gt;
    &lt;Grid&gt;
        &lt;TextBlock Text=&quot;This View has a POCO ViewModel&quot; TextWrapping=&quot;Wrap&quot;/&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_kbLwPqqL7i_tabid-csharpChildPOCOViewModel-cs" role="tabpanel" data-tab="tabid-csharpChildPOCOViewModel-cs" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (DevExpress.Mvvm.DataAnnotations)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm.DataAnnotations&quot;}" class="lang-csharp">using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;

namespace Example.ViewModel {
    public class ChildPOCOViewModel : ISupportParameter {
        [ServiceProperty(SearchMode=ServiceSearchMode.PreferParents)]
        protected virtual IMessageBoxService MessageBoxService { get { return null; } }
        public virtual object Parameter { get; set; }

        protected virtual void OnParameterChanged() {
            if(Parameter is string)
                MessageBoxService.Show(&quot;ChildPOCOViewModel: Parameter = &quot; + (string)Parameter);
        }
    }
}
</code></pre></section>