Back to Devexpress

MvvmContext

windowsforms-113969-cross-platform-app-development-winforms-mvvm-design-time-support-mvvmcontext.md

latest2.5 KB
Original Source

MvvmContext

  • Dec 09, 2024
  • 4 minutes to read

The MvvmContext component is the key tool in developing MVVM applications using the DevExpress MVVM Framework. The component’s API is described in help topics of the Concepts section. This topic will demonstrate the design-time functionality of the MvvmContext.

You can invoke the MvvmContext smart-tag by clicking the corresponding button at the top right corner of the component. Links of this smart-tag provide the following functionality.

  • Adding new ViewModels. To add a new ViewModel that is related to this View, click the ‘Add ViewModel’ link (see the figure below).

  • Assigning a specific ViewModel to the MvvmContext. Use the drop-down within the smart-tag to choose a ViewModel assigned to this component. If the ‘Show All Types’ check-box is clear, only public classes within the same file and namespaces containing .ViewModel are shown (except for classes, whose names end with ‘Service’, ‘Message’, ‘Helper’ and other key words). Otherwise, the drop-down displays all appropriate classes. The ‘Hide Namespace’ check box hides namespace names for the classes, displayed within the drop-down. Clear this check box if you want to see full class names.

  • Generating RibbonControl links for existing commands. If there is a button container (e.g., the Ribbon Control or Bar Manager) lying on the same form that hosts the MvvmContext component, the ‘Retrieve Commands’ link appears as the figure below illustrates.

  • Register services. Similar to the automatic generation of ribbon item links, the MvvmContext component finds all service-related controls in your View and registers corresponding services locally when you click the Retrieve Services link in the control smart tag. For example, if your View contains the DocumentManager component, the DocumentManagerService is registered. The Edit… link invokes the Service Editor (shown in the image below) that allows you to register new services or modify existing registrations. This editor is also invoked when you click the edit button for the MVVMContext.RegistrationExpressions collection in Visual Studio’s Properties window.