与WP7.5上的匿名对象绑定

问题描述 投票:1回答:1

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

我的文本框为空。我认为我的绑定语法有误。

c# silverlight windows-phone-7 data-binding
1个回答
2
投票

我认为您正在寻找{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(...并非一定会帮助您解决特定问题)

© www.soinside.com 2019 - 2024. All rights reserved.