tags:

views:

53

answers:

2

Hi. In a WPF app, what XAML code do I need to do the same job as this line of c#:

this.DataContext = this;

? Thanks

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

ViewModel is a public property in your code behind.

saurabh
+2  A: 

I think you could do:

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

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

Jon Skeet
Super, thanks. The x:Static was the thing I was missing.
Tom Davies