locked
Json DesignData ignores read only properties. RRS feed

  • Question

  • So the great thing about 8.1 apps is that you can use json in your DesignData, saving lots of time when working with Json api's. While it works great with get/set properties, I'm having trouble getting the design layout to bind to read only properties, despite the class type being set in the definition. It's just blank :(


    DesignData :

     d:DataContext="{Binding Source={d:DesignData Source=/SampleData.json, Type=local:MyViewModel}}"

    SampleData.json

    {
      "FirstName":"John",
      "LastName":"Doe"
    }

    MyViewModel Class

    public class MyViewModel
    {
       public string FirstName {get; set;}
       public string LastName {get; set;}
       public string FullName 
       {
         get {
           return FirstName + " " + LastName;
         }
       }
    }

    Xaml

    <TextBlock Text="{Binding FullName}" />

    Am I doing something incorrectly?


    • Edited by Jarem Tuesday, October 22, 2013 4:32 PM
    Tuesday, October 22, 2013 4:32 PM

Answers

  • The problem was that I needed to add IsDesignTimeCreatable=True to my design data parameters as follows:

    d:DataContext="{Binding Source={d:DesignData Source=/SampleData.json, Type=local:MyViewModel, IsDesignTimeCreatable=True}}"

    This resolved my issue.

    Thanks Kenny Y. from Microsoft!

    • Marked as answer by Jarem Tuesday, October 22, 2013 7:07 PM
    Tuesday, October 22, 2013 7:07 PM