2013-01-15 16 views
1

與匿名對象綁定在WP7.5,我創造了這樣一個DataContext:在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}" /> 

我的文本框爲空,我認爲我的綁定語法有一個mystake。

任何人都可以幫助我嗎?

非常感謝

+0

是什麼'this'指什麼?您可能還需要檢查您的輸出以獲取WPF綁定警告消息。 – JDB

+0

我的xamlFile被命名爲page1.xaml,並且位於我的cs頁面上,名爲page1.xaml.cs。這是Page1.xaml.cs實例。 –

+0

而且一件重要的事情是,如果我使「this.datacontext = ListOne」的綁定是好的。我的問題來自{one = ListOne,two = ListTwo}。 –

回答

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(......不,它會幫助你與這個特殊的問題)

+0

這是一個類,它們是屬性:) –

+0

在這種情況下,您可能需要考慮閱讀微軟的[指南](http://msdn.microsoft.com/en-us/library/vstudio/ms229002)的.aspx)。 – JDB

+0

感謝這個鏈接,但是,我試過{Binding One.m_strTypeTiers}沒有成功:( –

相關問題