无法将绑定设置为驻留在 TextBlock 中的运行
<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
:“双向绑定需要 Path 或 XPath。”
指定 Mode=OneWay
会导致奇怪的编译器错误:
标记“Binding”在 XML 命名空间“http://schemas.microsoft.com/winfx/2006/xaml”中不存在/presentation'.
有什么 xamly 方法可以解决这个问题吗?
<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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有找到原因,但这是你可以做到这一点而不会变得太尴尬的方法:
由于某种原因
导致运行时错误,但事实
并非如此。原因可能与当您对绑定“不明确”时有关,有某些后备行为会接管解释您的绑定。或者,这可能是一个真正的 MS Bug,它在
Run
控件上解释{Binding}
。I have not found a reason why, but this is how you can do it without it getting too awkward:
For some reason
causes the runtime error, but
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 theRun
control.发现了一个奇怪的解决方法:
Found a weird workarond: