How to set a value to display for bound properties in WPF design mode? – Stack Overflow

via How to set a value to display for bound properties in WPF design mode? – Stack Overflow

An easy way to get Design-time-data in Visual Studio 2010 is to use a design-datacontext.

Short example with a Window and a ViewModel, For DataContext, the d:DataContext will be used in Design-mode and the StaticResource will be used in runtime. You can also use a separate ViewModel for design but in this example I will use the same ViewModel for both.

<Window ...
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:local="clr-namespace:TheNamespaceContainsTheDesignModeViewModel;assembly=TheAssemblyOrProjectContainsYourViewModelClass"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance local:YourDesignModeViewModel, IsDesignTimeCreatable=True}">
    <Window.Resources>
        <local:MyViewModel x:Key="MyViewModel" />
    </Window.Resources>
    <Window.DataContext>
        <StaticResource ResourceKey="MyViewModel"/>
    </Window.DataContext>
    <StackPanel>
        <TextBox Text="{Binding MyText}"
                 Width="75"
                 Height="25"
                 Margin="6"/>
    </StackPanel>
</Window>

Hope this is helpful!

Nam.

Advertisements

4 responses to this post.

  1. Posted by Dạ Vũ on December 4, 2010 at 5:44 PM

    i begin learning ADO.NET and feel Entity Framework really userful. Can you tutorial something about it? Pleaze! ! ! I understand the way it action with data, i don’t know how to coding to run a simple application. Plzzz!

    Reply

    • I’d love to ^_^ Would you start a new post showing what you have done so far? If you don’t have a blog, please join with me writting on my blog.

      Reply

      • Posted by Dạ Vũ on December 5, 2010 at 6:13 PM

        i have many blogs but i just like design and coding for beautiful effects. If writing about technology or progaming, i worry they say : ” Teach one’s grandmother to suck eggs ” ^^. Also, my ability writing is so bad…

      • @Vu: Can I have your blogs’ url(s)?
        About tech/programming blog, it is an action of sharing so that 1) you can verify yourself, 2) your knowledge can help the follower. Don’t worry about “mother suck eggs” since there are hundreds of newbie looking for how to “suck eggs” indeed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: