I am confused with whn to use {RelativeSource Self} when binding. The below three bindings look the same to me, where MyText is a property in my view model.
<TextBlock Text = "{Binding Path=MyText RelativeSource{RelativeSource Self} }" />
<TextBlock Text = "{Binding MyText RelativeSource{RelativeSource Self} }" />
<TextBlock Text = "{Binding MyText }" />
When should I use Self in my binding? Thanks.
The first two are equivalent, and bind to the MyText property of the TextBlock itself. But of course, they don't work, because there is no MyText property on TextBlock.
The third binds to the MyText property of the current DataContext
Use RelativeSource.Self when you need to bind to a property of the current control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With