WP7:从 DataTemplate 内将数据绑定到 MainViewModel

发布于 2024-09-30 20:51:09 字数 110 浏览 1 评论 0原文

在 WP7 项目中,我需要将 DataTemplates(例如,Pivot TitleTemplate)中的控件数据绑定到 MainViewModel 上的顶级项目。这怎么能做到呢?

谢谢。

Within a WP7 project, I need to data-bind controls within DataTemplates (a Pivot TitleTemplate, for example) to top-level items on the MainViewModel. How can this be done?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

oО清风挽发oО 2024-10-07 20:51:09

这应该适用于 WP7 版本以及 Silverlight 4。使用绑定到视图本身(或可视化树上任何更高的命名节点)的元素,并引用绑定中的 DataContext.elementName

例如

<TextBox Text="{Binding ElementName=myViewName, Path=DataContext.SomeTitleProperty}"/>

This should work for WP7 version as well as Silverlight 4. Use an element binding to the view itself (or any named node higher up the visual tree) and refer to the DataContext.elementName in the binding.

e.g.

<TextBox Text="{Binding ElementName=myViewName, Path=DataContext.SomeTitleProperty}"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文