What is a DesignInstance in XAML

The design instance is used when the view is opened in the visual studio editor.

Say you have a view that uses a list view to display a list of products, and you use a template to display each product. Without a viewmodel, your view will not display anything, and you can't really see what the view will look like in the application.

You don't want to run your entire app, with all its dependencies from the editor. Instead supply a design instance, with some stub data that makes the view render some products. Think of it as some fake test data that makes your view render correctly in the editor.


You may define the view model for your view through a dependency injection framework like Cariburn or simply set the view model in the code behind therefore your view will run and work perfectly but since the view model is not explicitly defined in the view XAML file, the visual studio XAML designer does not have a clue where to navigate to when you want to navigate to the view model properties bound in the view. using DesignInstance with the right type will make the designer able to navigate to the view model properties for you.

Tags:

C#

Xaml

Mvvm