簡體   English   中英

Xamarin表單ListView ItemsSource問題

[英]Xamarin Forms ListView ItemsSource issue

我有一個ListView及其ItemsSource。

ListView IList = new ListView();
IList.ItemsSource = _routine_names; 

為了自定義我正在做的每個項目的數據模板:

IList.ItemTemplate = new DataTemplate(()=>
        {
            Label Routine_Name = new Label(); // should be_routine_names
            return new ViewCell
            {
                View = new StackLayout{
                    Children = {Routine_Name}
                }
            };
        });

運行此命令時,將顯示ListView,並且列表項確​​實存在(它們具有可以工作的onclick處理程序),但是沒有文本,該文本應為_routine_names中的任何內容。

我的問題是如何使DataTemplate中的Label成為_routine_names中的項目?

我添加DataTemplate的原因是,我可以添加滑動來刪除。

您可以只使用內置的TextCell來完成您想做的事情。 如果要在主行下方放置一個較小的文本行,則它具有可綁定的TextProperty和可選的DetailProperty。

IList.ItempTemplate = new DataTemplate(()=> 
{
    var textCell = new TextCell();
    textCell.ContextActions.Add(yourAction);
    textCell.SetBinding(TextCell.TextProperty, "."); 
    return textCell; 
}

IList.ItemsSource = _routine_names; 

yourAction的類型是菜單項的所看到這里

另外,請注意IList是System.Collection命名空間中類的名稱,因此我將在此使用其他名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM