Windows Store App Design-time DataContext

点点圈 提交于 2019-12-01 02:34:18

Okay, I've cracked it. The format for setting the DataContext should be:

d:DataContext="{Binding PropertyNameOfSubViewModel, Source={d:DesignInstance Type=myNamespace:ViewModelTypeName, IsDesignTimeCreatable=True}}"

I now leave the Page level DC as the DefaultViewModel. I then add another DC attribute to the layout root Grid element with the above correct DC design-time syntax.

The TextBlock then needs only the name of a property on the SubViewModel in its binding. So the fake data view models are roughyl like this:

public class DesignTimeDataHub : BindableBase // Probably doesn't need to be BindableBase.
{
    public CommonBindableFakeData CommonFakeData { // get set }
}

public class CommonBindableFakeData : BindableBase
{
    ctor { // set some default fake values }

    public string Title { // get set }
}

Here's what it looks like:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!