4

I have a view (usercontrol) that contains a listbox. At runtime the listbox will be populated with instances of another view (also a usercontrol). How can I populate the listbox in design-time (in Blend and Cider) with sample views that are themselves populated with sample data?

Omer Mor
  • 5,216
  • 2
  • 34
  • 39
  • Possible Duplicate: http://stackoverflow.com/questions/834283/is-there-a-way-to-check-if-wpf-is-currently-executing-in-design-mode-or-not – Amsakanna Jul 08 '10 at 09:29
  • It's not the same question. I'm trying to find a design-time way to populate a listbox with sample data without it appearing in runtime. – Omer Mor Jul 09 '10 at 10:57

2 Answers2

5

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.

Yusuf Tarık Günaydın
  • 3,016
  • 2
  • 27
  • 41
Goran
  • 6,798
  • 9
  • 41
  • 57
0

You might find the BookLibrary sample application of the WPF Application Framework (WAF) interesting. It uses the new design-time support of Visual Studio 2010 and Expression Blend 4. Please download the .Net4 version of WAF.

jbe
  • 6,976
  • 1
  • 43
  • 34