# View Models | WPF Controls | DevExpress Documentation

The View Model is a part of an MVVM application responsible for the interaction between the two other parts: Model and View.

## Base View Models

The DevExpress MVVM Framework contains base classes that you can use to create your View Models:

- [BindableBase](/WPF/17350/mvvm-framework/viewmodels/bindablebase)

    - Implements the **INotifyPropertyChanged** interface and allows you to implement bindable properties.

- [ViewModelBase](/WPF/17351/mvvm-framework/viewmodels/viewmodelbase)

    - A [BindableBase](/WPF/17350/mvvm-framework/viewmodels/bindablebase) descendant that offers commands, services, and interaction between View Models.

## Generated View Models

The MVVM Framework allows you to produce boilerplate code for your View Models, so that you do not need to implement each command or property:

- [Runtime-generated POCO View Models](/WPF/17352/mvvm-framework/viewmodels/runtime-generated-poco-viewmodels)

    - Use the **ViewModelSource.Create** method to create a descendant of your View Model class. The mechanism is based on the [Reflection Emit](https://learn.microsoft.com/dotnet/api/system.reflection.emit) and produces code at runtime.

- [View Models Generated at Compile Time](/WPF/402989/mvvm-framework/viewmodels/compile-time-generated-viewmodels)

    - Use attributes to generate a View Model. The mechanism is based on the [Source Generators](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.md) and produces code at compile time.

You can find the requirements for both techniques in the table below:

|  | POCO View Models generated at runtime | View Models generated at compile time |
| --- | --- | --- |
| C# | v6+ | v9+ |
| .NET Framework | v4.5.2+ | v4.6.1+ |
| .NET Core | v3.0+ | v3.0+ |

Note

[C# 9 is officially supported in .NET 5 and newer.](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version) You may encounter issues when you use earlier versions of .NET and .NET Framework.

The following table summarizes the differences between View Models generated at runtime and compile time:

|  | POCO View Models generated at runtime | View Models generated at compile time |
| --- | --- | --- |
| Execution time | Runtime | Compile time |
| Generated class | Descendant class | Partial class |
| Generated code access | ![no](/WPF/images/no.png) | Read-only .cs file |
| Debug access | ![no](/WPF/images/no.png) | ![yes](/WPF/images/yes.png) |
| VB support | ![yes](/WPF/images/yes.png) | ![no](/WPF/images/no.png) |

## Dependency Injection

To bind a view to a view model, create a MarkupExtension that resolves the correct ViewModel type:

- C#

<section id="tabpanel_zjDmjgPbV2_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code class="lang-csharp">public class DISource : MarkupExtension {
    public static Func&lt;Type, object, string, object&gt; Resolver { get; set; }

    public Type Type { get; set; }
    public object Key { get; set; }
    public string Name { get; set; }

    public override object ProvideValue(IServiceProvider serviceProvider) =&gt; Resolver?.Invoke(Type, Key, Name);
}
</code></pre></section>

Register the resolver at application startup:

- C#

<section id="tabpanel_zjDmjgPbV2-1_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code class="lang-csharp">protected override void OnStartup(StartupEventArgs e) {
    base.OnStartup(e);
    DISource.Resolver = Resolve;
}
object Resolve(Type type, object key, string name) {
    if(type == null)
        return null;
    if(key != null)
        return Container.ResolveKeyed(key, type);
    if(name != null)
        return Container.ResolveNamed(name, type);
    return Container.Resolve(type);
}
</code></pre></section>

Specify the DataContext in XAML in the following manner:

- XAML

<section id="tabpanel_zjDmjgPbV2-2_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">DataContext=&quot;{common:DISource Type=common:CollectionViewModel}&quot;
</code></pre></section>

### Examples

- Services:

      [View Example](https://github.com/DevExpress-Examples/wpf-mvvm-framework-use-services-with-dependency-injection)
- POCO:

      [View Example](https://github.com/DevExpress-Examples/wpf-mvvm-framework-register-poco-type-in-dependency-injection-container)

## View Model Interaction

- [Interaction of ViewModels](/WPF/17473/mvvm-framework/viewmodels/interaction-of-viewmodels)
- [Passing Data Between ViewModels (ISupportParameter)](/WPF/17448/mvvm-framework/viewmodels/passing-data-between-viewmodels-isupportparameter)
- [ViewModel Relationships (ISupportParentViewModel)](/WPF/17449/mvvm-framework/viewmodels/viewmodel-relationships-isupportparentviewmodel)
- [Messenger](/WPF/17474/mvvm-framework/messenger)