2010-10-01 59 views

回答

2

认为你可以这样做:

DataContext="{Binding RelativeSource={x:Static RelativeSource.Self}}" 

我刚刚试了一下,似乎工作...

编辑:正如在评论中指出,显然你也可以使用:

DataContext="{Binding RelativeSource={RelativeSource Self}}" 

...但我还没有尝试过。

+0

超级,谢谢。 x:Static是我错过的东西。 – 2010-10-01 10:38:18

+0

我会把它写成'RelativeSource = {RelativeSource Self}',稍微短一些。 – 2012-01-17 00:34:27

2
<UserControl.DataContext> 
    <Binding Path="ViewModel"></Binding> 
</UserControl.DataContext> 

视图模型是在后面代码中的公共财产。