开发者

Equivalent XAML line to this C#

In a WPF app, what开发者_运维技巧 XAML code do I need to do the same job as this line of c#:

this.DataContext = this;

? Thanks


I think you could do:

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

I've just tried it, and it seems to work...

EDIT: As noted in comments, apparently you can also use:

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

... but I haven't tried that.


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

ViewModel is a public property in your code behind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜