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.

Creating

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" 
                    TheNumber="89">
    <YourNamespace:Item.OtherItem>
        <YourNamespace:OtherItem OtherLineOne="Vestibulum cras sed"
                                 OtherLineTwo="Integer aptent praesent class dis"
                                 OtherLineThree="Adipiscing maecenas aliquam" />
    </YourNamespace:Item.OtherItem>
    <YourNamespace:Item.OtherItems>
        <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" />
    </YourNamespace:Item.OtherItems>
</YourNamespace:Item>

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; }
    }

Binding

Bind the design data to your control:
<UserControl x:Class="YourNameSpace.YourItemControl"
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           d:DataContext="{d:DesignData /SampleData/ItemSampleData.xaml}"
           DataContext="{Binding}">
..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: GeeksWithBlogs.net