开发者

WP7: Data Binding to MainViewModel from within a DataTemplate

开发者 https://www.devze.com 2023-01-23 08:33 出处:网络
Within a WP7 project, I need t开发者_运维知识库o data-bind controls within DataTemplates (a Pivot TitleTemplate, for example) to top-level items on the MainViewModel. How can this be done?

Within a WP7 project, I need t开发者_运维知识库o data-bind controls within DataTemplates (a Pivot TitleTemplate, for example) to top-level items on the MainViewModel. How can this be done?

Thanks.


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}"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号