Do you use design time data?

Last updated by Tom Bui [SSW] 4 months ago.See history

UPDATE: XAML Previewer was deprecated in Visual Studio 2019. For .NET MAUI use Hot Reload

The XAML previewer in Visual Studio is a useful tool for designing your Xamarin UI. One limitation is that often your controls are bound to properties in your ViewModel (see rule: Do you use the MVVM pattern?), meaning that you can't see what your UI will look like with the data loaded, without building and running your app.

design time bad
Figure: Bad example - Screenshot of XAML previewer with blank controls

A simple solution to this problem is to use design-time data. By importing the relevant namespaces into your XAML file, you can specify placeholder data that the previewer interprets to show how your UI will render with data loaded.

These are the namespaces to import, and the declaration to use them:

xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"

design time good
Figure: Good example - Screenshot of XAML previewer with design-time data

If your Xamarin and Visual Studio versions are up to date these namespaces will automatically be included in any new XAML file.

We open source. Powered by GitHub