为xaml应用程序创建设计时数据

为xaml应用程序创建设计时数据,xaml,windows-phone-8.1,design-time-data,Xaml,Windows Phone 8.1,Design Time Data,我有一个windows phone运行时应用程序,它厌倦了使用Expression Blend生成设计时数据。问题是我的一些类嵌套了类,设计数据将无法编译。下面是我用来生成设计时数据的类 public class stats { public class Pageviews { public int regular { get; set; } public int threat { get; set; } public int cr

我有一个windows phone运行时应用程序,它厌倦了使用Expression Blend生成设计时数据。问题是我的一些类嵌套了类,设计数据将无法编译。下面是我用来生成设计时数据的类

public class stats
{
    public class Pageviews
    {
        public int regular { get; set; }
        public int threat { get; set; }
        public int crawler { get; set; }
    }

    public class Uniques
    {
        public int regular { get; set; }
        public int threat { get; set; }
        public int crawler { get; set; }
    }

    public class TrafficBreakdown
    {
        public Pageviews pageviews { get; set; }
        public bool estimated { get; set; }
        public Uniques uniques { get; set; }
    }

    public class BandwidthServed
    {
        public double cloudflare { get; set; }
        public double user { get; set; }
    }

    public class RequestsServed
    {
        public int cloudflare { get; set; }
        public int user { get; set; }
    }

    public class Obj
    {
        public long cachedServerTime { get; set; }
        public long cachedExpryTime { get; set; }
        public TrafficBreakdown trafficBreakdown { get; set; }
        public BandwidthServed bandwidthServed { get; set; }
        public RequestsServed requestsServed { get; set; }
        public bool pro_zone { get; set; }
        public long currentServerTime { get; set; }
        public int interval { get; set; }
        public long zoneCDate { get; set; }
        public string userSecuritySetting { get; set; }
        public int dev_mode { get; set; }
        public int ipv46 { get; set; }
        public int ob { get; set; }
        public string cache_lvl { get; set; }
        public string outboundLinks { get; set; }
    }

    public class Result
    {
        public long timeZero { get; set; }
        public long timeEnd { get; set; }
        public int count { get; set; }
        public bool has_more { get; set; }
        public List<Obj> objs { get; set; }
    }

    public class Response
    {
        public Result result { get; set; }
    }

    public class RootObject
    {
        public Response response { get; set; }
        public string result { get; set; }
        public string msg { get; set; }
        public string err_code { get; set; }
    }
}
公共类统计信息
{
公共类网页浏览量
{
公共int正则{get;set;}
公共int威胁{get;set;}
公共int爬虫程序{get;set;}
}
公共类大学
{
公共int正则{get;set;}
公共int威胁{get;set;}
公共int爬虫程序{get;set;}
}
公共类流量细分
{
公共页面浏览页面浏览{get;set;}
公共布尔估计值{get;set;}
公共唯一性唯一性{get;set;}
}
公共类带宽服务
{
公共双cloudflare{get;set;}
公共双用户{get;set;}
}
已提供公共类请求
{
public int cloudflare{get;set;}
公共int用户{get;set;}
}
公共类Obj
{
公共长缓存服务器时间{get;set;}
公共长缓存时间{get;set;}
公共交通中断交通中断{get;set;}
公共带宽服务带宽服务{get;set;}
公共请求服务请求服务{get;set;}
公共bool pro_区域{get;set;}
公共长currentServerTime{get;set;}
公共整数间隔{get;set;}
公共长区域日期{get;set;}
公共字符串userSecuritySetting{get;set;}
公共int dev_模式{get;set;}
公共int ipv46{get;set;}
公共int ob{get;set;}
公共字符串缓存\u lvl{get;set;}
公共字符串外部链接{get;set;}
}
公开课成绩
{
公共长时间零{get;set;}
公共长时间结束{get;set;}
公共整数计数{get;set;}
公共布尔还有{get;set;}
公共列表对象{get;set;}
}
公众课堂反应
{
公共结果结果{get;set;}
}
公共类根对象
{
公共响应{get;set;}
公共字符串结果{get;set;}
公共字符串msg{get;set;}
公共字符串错误代码{get;set;}
}
}
这是设计时.xaml文件

<ViewModels:MainViewModel.Stats>
    <Data:stats+Obj cache_lvl="Adipiscing nam phasellus" dev_mode="83" ipv46="75" interval="55" ob="47" outboundLinks="Parturient class aliquam vestibulum vestibulum" pro_zone="False" userSecuritySetting="Cras vestibulum curabitur">
        <Data:stats+Obj.bandwidthServed>
            <Data:stats+BandwidthServed cloudflare="500.26" user="349.37"/>
        </Data:stats+Obj.bandwidthServed>
        <Data:stats+Obj.cachedServerTime>
            <System:Int64/>
        </Data:stats+Obj.cachedServerTime>
        <Data:stats+Obj.cachedExpryTime>
            <System:Int64/>
        </Data:stats+Obj.cachedExpryTime>
        <Data:stats+Obj.currentServerTime>
            <System:Int64/>
        </Data:stats+Obj.currentServerTime>
        <Data:stats+Obj.requestsServed>
            <Data:stats+RequestsServed cloudflare="18" user="44"/>
        </Data:stats+Obj.requestsServed>
        <Data:stats+Obj.trafficBreakdown>
            <Data:stats+TrafficBreakdown estimated="True">
                <Data:stats+TrafficBreakdown.pageviews>
                    <Data:stats+Pageviews crawler="10" regular="41" threat="19"/>
                </Data:stats+TrafficBreakdown.pageviews>
                <Data:stats+TrafficBreakdown.uniques>
                    <Data:stats+Uniques crawler="99" regular="66" threat="39"/>
                </Data:stats+TrafficBreakdown.uniques>
            </Data:stats+TrafficBreakdown>
        </Data:stats+Obj.trafficBreakdown>
        <Data:stats+Obj.zoneCDate>
            <System:Int64/>
        </Data:stats+Obj.zoneCDate>
    </Data:stats+Obj>
</ViewModels:MainViewModel.Stats>

它表示stats+.Obj在名称中无效。有人有办法吗


提前感谢。

我看到的第一个问题是
+
字符在XML名称中是非法的

编辑:使用Blend中的设计选项卡从类生成示例数据(只需单击设计选项卡中的“从类生成示例数据”并选择根类)。 我使用您的类生成的示例数据:

<App7:Obj.bandwidthServed>
  <App7:BandwidthServed cloudflare="130.23" user="116.56"/>
</App7:Obj.bandwidthServed>
<App7:Obj.cachedServerTime>
  <System:Int64/>
</App7:Obj.cachedServerTime>
<App7:Obj.cachedExpryTime>
  <System:Int64/>
</App7:Obj.cachedExpryTime>
<App7:Obj.currentServerTime>
  <System:Int64/>
</App7:Obj.currentServerTime>
<App7:Obj.requestsServed>
  <App7:RequestsServed cloudflare="78" user="56"/>
</App7:Obj.requestsServed>
<App7:Obj.trafficBreakdown>
  <App7:TrafficBreakdown estimated="True">
    <App7:TrafficBreakdown.pageviews>
      <App7:Pageviews crawler="75" regular="13" threat="11"/>
    </App7:TrafficBreakdown.pageviews>
    <App7:TrafficBreakdown.uniques>
      <App7:Uniques crawler="19" regular="76" threat="32"/>
    </App7:TrafficBreakdown.uniques>
  </App7:TrafficBreakdown>
</App7:Obj.trafficBreakdown>
<App7:Obj.zoneCDate>
  <System:Int64/>
</App7:Obj.zoneCDate>

为什么不直接使用PageDataContext并使用POCO在构造函数中创建伪数据,如下所示。VS2103Designer完美地显示了设计时的数据

这是XAML

<Page.DataContext>
    <ViewModel:BookVM />
</Page.DataContext>

当您的类声明位于另一个类声明(嵌套)中时,XAML引擎似乎无法正确引用它。声明需要位于命名空间的根。我想这是一个bug

我还可以使用什么字符访问嵌套类。这是我以前使用的解决方案,我想我会恢复。
public class BookVM : ViewModelBase
{
    public BookVM()
    {
       if (IsInDesignMode)
       { 
          var books = new List<Book>();
          books.Add(new Book(){ Name = "Test"});
          books.Add(new Book(){ Name = "Test2"});
          books.Add(new Book(){ Name = "Test3"});

          Books = books;
      }
    }

    List<Person> _books;
    public List<Person> BookList
    {
        get{ return _books;}
        set
        {
           _books = value; 
            OnPropertyChanged();
        }
    }
} 

}
public class ViewModelBase : INotifyPropertyChanged
{
    public bool IsInDesignMode
    {
        get 
        {
            return DesignMode.DesignModeEnabled; 
        }
    }

    bool _isBusy;
    public bool IsBusy
    {
        get 
        {
            return _isBusy;
        }
        set 
        {
            _isBusy = value;
            OnPropertyChanged();
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged([CallerMemberName]string propertyName="")
    {
        var handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName));
    }
}