windows 8 - How to have DesignTime data in WinRT XAML? -


how can designtime data in winrt xaml designer shows sample data?

simple enough.

create model this:

public class fruit  {     public string name { get; set; } } 

create base viewmodel this:

public class baseviewmodel  {     public observablecollection<fruit> fruits { get; set; } } 

create real viewmodel this:

public class realviewmodel : baseviewmodel {     public realviewmodel()     {         if (!windows.applicationmodel.designmode.designmodeenabled)             loaddata();     }      public void loaddata()     {         // todo: load service     } } 

create fake-data viewmodel this:

public class fakeviewmodel : baseviewmodel {     public fakeviewmodel()     {         this.fruits = new observablecollection<fruit>         {             new fruit{ name = "blueberry"},             new fruit{ name = "apple"},             new fruit{ name = "banana"},             new fruit{ name = "orange"},             new fruit{ name = "strawberry"},             new fruit{ name = "mango"},             new fruit{ name = "kiwi"},             new fruit{ name = "rasberry"},             new fruit{ name = "blueberry"},         };     } } 

do in xaml:

<page.datacontext>     <local:realviewmodel /> </page.datacontext>  <d:page.datacontext>     <local:fakeviewmodel /> </d:page.datacontext> 

have fun!

ps: can attempt use d:designdata. approach works. feel not straight forward. in end, it's how it. either way, don't miss out on deisgntime data!


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -