<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>
抛出
InvalidOperationException
:“双向绑定(bind)需要 Path 或 XPath。”指定
Mode=OneWay
,导致一个奇怪的编译器错误:The tag 'Binding,' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
有什么方法可以解决这个问题吗?
最佳答案
我还没有找到原因,但这就是你如何做到这一点而不会变得太尴尬:
<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>
由于某些原因
<Run Text="{Binding}" />
导致运行时错误,但是
<Run Text="{Binding Path=.}" />
才不是。原因可能与您对绑定(bind)“模棱两可”有关,某些后备行为会接管来解释您的绑定(bind)。或者,这是一个真正的 MS 错误,带有解释
{Binding}
在 Run
控制。
关于wpf - 无法将绑定(bind)设置为驻留在 TextBlock 中的运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4481386/