<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="This is my text">
<TextBlock>
<Run Text="{Binding}"/>
</TextBlock>
</Window>
Throws InvalidOperationException
: "Two-way binding requires Path or XPath."
Specifying Mode=OneWay
, leads to a weird compiler error:
The tag 'Binding,' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
Is there any xamly way to fix this?
I have not found a reason why, but this is how you can do it without it getting too awkward:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="This is my text">
<TextBlock>
<Run Text="{Binding Path=.}"/>
</TextBlock>
</Window>
For some reason
<Run Text="{Binding}" />
causes the runtime error, but
<Run Text="{Binding Path=.}" />
does not. The reason might have something to do with when you are "ambiguous" with your bindings, there are certain fallback behaviors that take over to interpret your binding. Or perhaps, this is a genuine MS Bug with interpreting {Binding}
on the Run
control.