How to set properties of a d:DesignInstance in XAML?

Posted by Scott Bilas on Stack Overflow See other posts from Stack Overflow or by Scott Bilas
Published on 2010-04-26T20:49:27Z Indexed on 2010/04/26 20:53 UTC
Read the original article Hit count: 894

Filed under:
|

I'm using the new d:DesignInstance feature of the 4.0 series WPF tools. Works great!

Only issue I'm having is: how can I set properties on the instance? Given something like this:

<Grid d:DataContext="{d:DesignInstance plugin:SamplePendingChangesViewModel, IsDesignTimeCreatable=True}"/>

How can I set properties on the viewmodel, aside from setting them in its default ctor or routing it through some other object initializer?

I gave this a try but VS gives errors on compile "d:DataContext was not found":

<Grid>
    <d:DataContext>
        <d:DesignInstance IsDesignTimeCreatable="True">
            <plugin:SamplePendingChangesViewModel ActiveTagIndex="2"/>
        </d:DesignInstance>
    </d:DataContext>

For the moment I'm going back to using a resource and 'd:DataContext={StaticResource SampleData}', where I can set the properties in the resource.

Is there a way to do it via a d:DesignInstance?

© Stack Overflow or respective owner

Related posts about xaml

Related posts about wpf