Back to Devexpress

MVVMContextCompositionRoot Class

windowsforms-devexpress-dot-utils-dot-mvvm-b530fbcb.md

latest2.7 KB
Original Source

MVVMContextCompositionRoot Class

Allows you to bind data types created by DevExpress MVVM Framework at runtime to a dependency injection framework.

Namespace : DevExpress.Utils.MVVM

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
public static class MVVMContextCompositionRoot
vb
Public Module MVVMContextCompositionRoot

Remarks

The MVVMContextCompositionRoot class exposes the ViewModelCreate event that allows you to bind data types created by DevExpress MVVM Framework at runtime to a dependency injection framework (for example, Ninject).

csharp
// Retrieve the live POCO ViewModel instance with the Ninject kernel
//regular event
mvvmContext1.ViewModelCreate += MVVMContext_ViewModelCreate;
void MVVMContext_ViewModelCreate(object sender, DevExpress.Utils.MVVM.ViewModelCreateEventArgs e) {
    // kernel.Bind<SamuraiViewModel>().To(e.RuntimeViewModelType);
    // e.ViewModel = kernel.Get<SamuraiViewModel>();
    e.ViewModel = kernel.Get(e.RuntimeViewModelType);
}
//static event
MVVMContextCompositionRoot.ViewModelCreate += (s,e)=> {
    e.ViewModel = kernel.Get(e.RuntimeViewModelType);
};
vb
' Retrieve the live POCO ViewModel instance with the Ninject kernel
'regular event
AddHandler mvvmContext1.ViewModelCreate, AddressOf MVVMContext_ViewModelCreate
void MVVMContext_ViewModelCreate(Object sender, DevExpress.Utils.MVVM.ViewModelCreateEventArgs e)
    ' kernel.Bind<SamuraiViewModel>().To(e.RuntimeViewModelType);
    ' e.ViewModel = kernel.Get<SamuraiViewModel>();
    e.ViewModel = kernel.Get(e.RuntimeViewModelType)
'static event
AddHandler MVVMContextCompositionRoot.ViewModelCreate, Sub(s,e) e.ViewModel = kernel.Get(e.RuntimeViewModelType)

Read the following topic for detailed information and examples: ViewModel Management.

Inheritance

Object MVVMContextCompositionRoot

See Also

MVVMContextCompositionRoot Members

DevExpress.Utils.MVVM Namespace