Geeks With Blogs
| Home |
I just have to write about design data because it makes my life so much easier. More than I could imaging before I started to use it.

There are two ways for creating design data; Either you let Expression Blend do it for you or you just write your own in visual studio. Basically it is a xml file representing your model.


The fast way:

- Right click a view (or any xaml-file) in your project and choose "Open in Expresion Blend"
- Click here:

- Choose "Create sample data from class" and then pick your class. Piece of cake.

The slow and hardcore way:

- Add a folder to your solution. Let's call it SampleData (or whatever you want).
- Add a class called something like ItemSampleData.xaml.
- Set the property BuildAction to DesignData on ItemSampleData.xaml

Example: ItemSampleData.xaml

<YourNamespace:Item xmlns:YourNamespace="clr-namespace:YourNamespace"
                    LineOne="Aenean nam mauris"
                    LineTwo="Nullam curabitur" 
        <YourNamespace:OtherItem OtherLineOne="Vestibulum cras sed"
                                 OtherLineTwo="Integer aptent praesent class dis"
                                 OtherLineThree="Adipiscing maecenas aliquam" />
        <YourNamespace:OtherItem OtherLineOne="Curae parturient est duis hac"
                                 OtherLineTwo="Nunc amet"
                                 OtherLineThree="Auctor accumsan" />
        <YourNamespace:OtherItem OtherLineOne="Ante bibendum congue leo vestibulum"
                                 OtherLineTwo="Dictumst arcu cursus nec" 
                                 OtherLineThree="Phasellus donec etiam mus" />

Example: The fancy classes

    public class Item
        public string LineOne { get; set; }
        public string LineTwo { get; set; }
        public int TheNumber { get; set; }
        public OtherItem OtherItem { get; set; }
        public List<OtherItem> OtherItems { get; set; }

    public class OtherItem
        public string OtherLineOne { get; set; }
        public string OtherLineTwo { get; set; }
        public string OtherLineThree { get; set; }


Bind the design data to your control:
<UserControl x:Class="YourNameSpace.YourItemControl"
           d:DataContext="{d:DesignData /SampleData/ItemSampleData.xaml}"
..or in a smaller context..
<ListBox ItemsSource="{Binding OtherItems}" 
         d:DataContext="{d:DesignData /SampleData/ItemSampleData.xaml}" />

Posted on Thursday, June 9, 2011 11:03 PM | Back to top

Comments on this post: Design data

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © sarahkjork | Powered by: