在WP7.5上,我创建了这样的数据上下文:
this.DataContext = new { One = listOne, Two = listTwo};
在我的XAML代码上,我尝试了此操作:
<TextBlock Text="{Binding listOne.m_strTypeTiers}" Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock Text="{Binding listTwo.m_strTypeTiers}" Style="{StaticResource PhoneTextNormalStyle}" />
我的文本框为空。我认为我的绑定语法有误。
我认为您正在寻找{Binding One.m_strTypeTiers}
但是这取决于listOne和listTwo是什么。它们是否具有名为m_strTypeTiers的属性?如果m_strTypeTiers是一个字段,那么您将无法对其进行数据绑定。数据绑定仅适用于属性(by default)。
UPDATE哎呀。 Silverlight does not support binding to anonymous types。我当时正在考虑将WPF用于桌面应用程序。 Windows Phone 7 uses Silverlight非常相似,但在某些重要方面有所不同。我认为您不走运-您需要定义一个具体的类。
[您可能会发现本文对以后有所帮助:Contrasting Silverlight and WPF(...并非一定会帮助您解决特定问题)