开发者

Equivalent XAML line to this C#

开发者 https://www.devze.com 2023-01-18 20:41 出处:网络
In a WPF app, what开发者_运维技巧 XAML code do I need to do the same job as this line of c#: this.DataContext = this;

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

精彩评论

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