Wpf 无法将绑定设置为驻留在TextBlock中的运行
抛出InvalidOperationException:“双向绑定需要路径或XPath。” 指定Wpf 无法将绑定设置为驻留在TextBlock中的运行,wpf,binding,textblock,bindable,Wpf,Binding,Textblock,Bindable,抛出InvalidOperationException:“双向绑定需要路径或XPath。” 指定Mode=OneWay,会导致奇怪的编译器错误: XML命名空间中不存在标记“Binding”http://schemas.microsoft.com/winfx/2006/xaml/presentation“。 有没有办法解决这个问题?找到了一个奇怪的解决方法: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/pr
Mode=OneWay
,会导致奇怪的编译器错误:
XML命名空间中不存在标记“Binding”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}"/>
</TextBlock>
</Window>
我还没有找到原因,但这就是如何做到不让事情变得太尴尬的方法:
<Window
x:Name="Me"
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 DataContext, ElementName=Me}"/>
</TextBlock>
</Window>
出于某种原因
<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}" />
没有。原因可能与当您对绑定“不明确”时有关,有些回退行为会接管您的绑定。或者,这可能是一个真正的MS Bug,在运行
控件上解释{Binding}
<Run Text="{Binding Path=.}" />