Namek Dev
a developer's log
NamekDev

WPF/Silverlight Design Data without XAML

February 19, 2014

Here’s a class for our sample data. That’s where the data should go into.

public class MainViewModelDesignData : MainViewModel {
    public MainViewModelDesignData() {
        // TODO: instantiate your sample data
    }
}

In App.xml define your namespace:

xmlns:models="clr-namespace:YourApp.ViewModels"

and then:

<Application.Resources>
    <models:MainViewModel x:Key="DesignDataContext" />
</Application.Resources>

The last step - instantiate sample data as DesignContext. You can do it in your Window, Page or whatever. I did it in MainPage.xaml in my Windows Phone 7 application:

<phone:PhoneApplicationPage.DataContext>
    <models:MainViewModelDesignData />
</phone:PhoneApplicationPage.DataContext>

Our sample data is bound to whole page. Use it like every other binding.

csharp
comments powered by Disqus