2016-03-14 52 views
0

我新上Xamarin.Forms,我試圖用EntryCell如何EntryCell添加到Xamrin.Forms內容

AccountId = new EntryCell {Label="Account Id", Text = CustomersPage.staticCustomer.AccountId}; 

當我嘗試添加到頁面的內容是這樣的:

Content = new StackLayout { 
    Children = { 
     AccountId    
    } 
}; 

我得到這個錯誤:

The best overloaded Add method 'System.Collections.Generic.ICollection.Add(Xamarin.Forms.View)' for the collection initializer has some invalid arguments

爲什麼我不能添加EntryCell直接就像Entry?我怎樣才能添加它?

+1

我不認爲EntryCell可以直接插入StackLayout。我相信它屬於一個TableView。請參閱此處的文檔,https://developer.xamarin.com/api/type/Xamarin.Forms.EntryCell/。 – Bearcat9425

+0

@ Bearcat9425謝謝...實際上,現在我做同樣的事情,我使用TableView,但我想知道爲什麼? –

回答

0

Actullay我正在尋找而去使用標籤和文本在同一時間所以 作爲@Arkadiusz說

我使用的TableView這樣的:

TableView tb = new TableView(); 
    tb.Root = new TableRoot() { new TableSection("Info") { AccountId }};   
    Content = new StackLayout { Children={ tb, ProcessToCheckOut } } 

或 我需要用戶輸入& &標籤,而不是EntryCell和更改stackLayout方向水平

1

EntryCell並非來自View,因此您不能將其作爲孩子添加到StackLayout兒童收藏中。通常由於性能原因,使用ListView(也使用TableView)控制來使用 EntryCellEntryCell派生自Cell,其提供對視覺元素的描述而不是視覺元素。

另一方面Entry派生自View,因此您可以將其添加到StackLayout

+0

@ArkaduisZ K ...謝謝。但我想使用EntryCell,因爲我需要在同一時間使用標籤和文本..我用這樣的TableView ..可以請你用我的代碼在你的答案TableView tb = new TableView(); tb.Root = new TableRoot(){ new TableSection(「Tcetra Info」){ AccountId }}; 含量=新StackLayout { 兒童= { \t \t \t \t TB, ProcessToCheckOut \t \t \t \t} }; –

+0

你總是可以編輯你的問題,並添加額外的問題/解釋:) –

+3

爲什麼你不能創建一個標籤和條目?如果你並排需要它們,你可以將你的stackLayout方向選項設置爲Horizo​​ntal。 – Bearcat9425