Question

In a MVVM based application, what options do I have to provide ViewModel data at design time, so our designers can actually see something in Blend3 (and VS 2008). How are you doing this? Can I utilize mc:ignorable for this somehow?

Was it helpful?

Solution

Yes, Expression Blend can help you with this. Use the "Data" tab to create sample data that has the same shape as your production data. When you create the data source, be sure to uncheck "Enable sample data when application is running".

Sample Data http://www.smips.com/brad/stackoverflow/design-model1.jpg

After you've created your sample data, set the DataContext of your page to the sample data in the XAML. This will let the designers see the sample data when they open the page in Blend.

<navigation:Page DataContext={StaticResource MyFakeDesignData}

In the code for the Loaded handler, write code to set the DataContext to the real model. Since this code will only run when the app is running, and you've told your sample data to not be available when the app is running, this means the running app will get the real data.

private void Home_Loaded(object sender, RoutedEventArgs e)
{
    DataContext = new MyRealViewModel();
}

OTHER TIPS

Using VS2010 you can use Design-Time attributes (works for both SL and WPF). I usually have a mock data-source anyway so it's just a matter of:

  • Adding the namespace declaration

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

  • Adding the mock data context to window/control resources

    <UserControl.Resources> <ViewModels:MockXViewModel x:Key="DesignViewModel"/> </UserControl.Resources>

  • Setting design-time data context

    <Grid d:DataContext="{Binding Source={StaticResource DesignViewModel}}"> ...

Works well enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top