如何在数组中获取查询值,并在sqlite xamarin表单中显示标签文本
本文关键字:表单 sqlite xamarin 显示 文本 标签 并在 数组 获取 查询 | 更新日期: 2023-09-27 18:06:34
我在数组中返回我的查询值,如
public IEnumerable<ItemTable> SearchItem(string itemName)
{
return (from i in
_connection.Table<ItemTable>()
where i.ItemName.StartsWith(itemName)
select i).ToArray();
}
谁能告诉我如何得到这个数组值,当我调用这个函数意味着如何得到这个结果显示在屏幕上标签的文本。请回复
下面是一个示例;
public IEnumerable<ItemTable> SearchItem(string itemName)
{
return (from i in
_connection.Table<ItemTable>()
where i.ItemName.StartsWith(itemName)
select i).ToArray();
}
private string DisplayItemsInLabel(string itemName)
{
var searchedItems = this.SearchItem(itemName); // get items using above method that you have written already.
// get name and price
var displayableItems = searchedItems.Select(i => string.Format("Name :{0}, Price :{1}", i.Name, i.Price));
// create a formatted string using name and the price. so that we can display it in a label.
return string.Join(Environment.NewLine, displayableItems);
}
public LabelPage()
{
InitializeComponent();
var layout = new StackLayout { Padding = new Thickness(5, 10) };
this.Content = layout;
//display contents in a label
var label = new Label { Text = DisplayItemsInLabel("MyItem"), TextColor = Color.FromHex("#77d065"), FontSize = 20 };
layout.Children.Add(label);
}