出现绑定错误但没有绑定集?
我的 WPF 窗口中有这个控件;
<TextBlock Name="txtMyTextBlock"
Text="{x:Static Resources:Strings.SOME_LABEL_IDENTIFIER}"
Margin="10,10,10,0" HorizontalAlignment="Left" VerticalAlignment="Top"
Style="{StaticResource WindowTitleStyle}" />
当加载窗口时,我在输出窗口中收到此错误;
Windows.Data 错误:40:BindingExpression 路径错误:“文本”属性 在“对象”“MyViewModelClass”(HashCode=7754709)”上找不到。 绑定表达式:路径=文本; DataItem='MyViewModelClass' (哈希码=7754709);目标元素是“TextBlock” (名称='txtMyTextBlock');目标属性为“NoTarget”(类型“Object”)
据我所知,TextBlock“txtMyTextBlock”上的“Text”属性设置为嵌入式资源字符串...为什么我会在这里收到绑定错误?
I have this control in my WPF window;
<TextBlock Name="txtMyTextBlock"
Text="{x:Static Resources:Strings.SOME_LABEL_IDENTIFIER}"
Margin="10,10,10,0" HorizontalAlignment="Left" VerticalAlignment="Top"
Style="{StaticResource WindowTitleStyle}" />
and when the window is loaded, I get this error in the Output Window;
Windows.Data Error: 40 : BindingExpression path error: 'Text' property
not found on 'object' ''MyViewModelClass' (HashCode=7754709)'.
BindingExpression:Path=Text; DataItem='MyViewModelClass'
(HashCode=7754709); target element is 'TextBlock'
(Name='txtMyTextBlock'); target property is 'NoTarget' (type 'Object')
As far as I can tell, the 'Text' property on the TextBlock 'txtMyTextBlock' is set to an Embedded Resource string... why am I getting binding errors here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的 Text="" 中,您绑定到静态资源。这是可以做到的,但你的语法是错误的。你想要的是这样的:
in your Text="" you are binding to a static resource. this can be done, but your syntax is wrong. what you want is something like this:
here is a good walk-though/tutorial
问题不应该出现在这段代码中,
x:Static
不会导致绑定错误,我怀疑您应用的样式中存在失败的绑定,例如即使样式设置器没有优先级 我从中收到错误绑定:
The problem should not be in this bit of code,
x:Static
does not cause binding errors, i suspect that there is a failing binding in the style you applied, e.g.Even though the style setter does not have precedence i get an error from that binding: