0
我想根據搜索從我的視頻類中返回列表視圖條目。在Videos類中,有單獨的Video對象具有多個屬性,如標題,視圖,作者和上傳日期。Xamarin自定義列表視圖搜索
如何查詢視頻以基於搜索欄返回視頻對象? 最後,我希望它根據標題屬性的查詢返回視頻對象的所有屬性。
如果title.contatins(關鍵字): 返回視頻對象
Homepage.xaml.cs:
public partial class Homepage : ContentPage
{
List<Video> Videos = new List<Video>
{
new Video
{
Title = "Video 1",
Author = "FedEx",
Views = 322,
Upload_DateTime = new DateTime(1996, 8, 26),
ImageURL = "icon.png",
},
new Video
{
Title = "Video 2",
Author = "FedEx",
Views = 554,
Upload_DateTime = new DateTime(2017, 1, 23),
ImageURL = "icon.png",
},
new Video
{
Title = "Video 3",
Author = "FedEx",
Views = 23,
Upload_DateTime = new DateTime(2012, 3, 11),
ImageURL = "icon.png",
},
};
public Homepage()
{
InitializeComponent();
VideoListView.ItemsSource = Videos;
}
private void MainSearchBar_Pressed(object sender, EventArgs e)
{
var keyword = MainSearchBar.Text;
VideoListView.ItemsSource = Videos.Where(Title = keyword);
}
}
Video.cs:
class Video
{
public string Title { get; set; }
public string Author { get; set; }
public int Views { get; set; }
public DateTime Upload_DateTime { get; set; }
public string ImageURL { get; set; }
}
注意:MainSearchBar_Pressed事件處理程序是拋出荷蘭國際集團我送行