This project has moved. For the latest updates, please go here.

Design-Time Data

There are many ways to provide design-time data. While the "locator" method is quite popular, Jounce suggests (but doesn't require) a more straightforward manner.

For a non-interfaced approach that uses compiler directives, read this post:

Clean Design-Time Friendly View Models: A Walkthrough

First, define an interface for your view model:

public interface IMainViewModel
    string Welcome { get; }

Next, create a folder called SampleData and add a DesignViewModel class that inherits the interface. Don't worry about property changed events and don't implement any methods, simply provide the data points where they are needed.

public class DesignTimeViewModel : IMainViewModel  
    public string Welcome
        get { return "Welcome to the designer for Jounce."; }

Finally, create your actual view model inheriting from one of the base view models in Jounce.

public class MainViewModel : BaseViewModel, IMainViewModel 
    public string Welcome
        get { return "Welcome to Jounce."; }

The runtime view model will be bound by the Jounce framework. For the design-time view model, just add a small piece of xaml to the view.

First, declare a sample data namespace. Make sure the design-time namespaces are declared as well.

<UserControl xmlns:d=""

Next, use the design-time data context to specify the design-time view model. You must compile the project before the data will show, but it then should show immediately in the browser when you bind to properties:

<Grid x:Name="LayoutRoot" Background="White" d:DataContext="{d:DesignInstance sampleData:DesignTimeViewModel, IsDesignTimeCreatable=True}">
    <TextBlock Text="{Binding Welcome}"/>

Last edited Mar 27, 2011 at 3:25 PM by jeremylikness, version 3


No comments yet.