Can the MVVM-Light ViewModelLocator be used in nested ViewModels?

做~自己de王妃 提交于 2019-12-04 19:28:08

I encounter the same situation in VS 2010. A partial workaround I JUST discovered...

In your UserControl, change DataContext to d:DataContext

<UserControl x:Class="MyProject.Views.MyUserControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         d:DataContext="{Binding MyNestedViewModel, Source={StaticResource Locator}}"
>
<Grid>
    <TextBlock>Hello</TextBlock>
</Grid>
</UserControl>

Unfortunately, I can't get it to display data in the UserControl YET, just the UserControl itself.

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