我的帶有位置自動建議的后端代碼運行良好(我可以看到它從我后端的串列中讀取位置)現在我想在用戶開始使用 Text_Changed 選項在條目中輸入內容時向用戶顯示該串列。下面是我的 Text_Changed 方法(“locationText_Changed”)。現在如何在用戶開始輸入一些文本時在 UI 中向用戶顯示預測串列?
后臺代碼:
private async void locationText_Changed(object sender, TextChangedEventArgs e)
{
if (location == null)
{
await GetLocation();
}
string formattedLocation = string.Format("{0},{1}", location.Latitude, location.Longitude);
List<Prediction> predictionList = await VenueLogic1.GetVenues1(e.NewTextValue, formattedLocation);
還有我的用戶界面:
<StackLayout BackgroundColor="BlanchedAlmond" >
<Entry x:Name="locationEntry"
TextChanged="locationText_Changed"
Placeholder="Enter Address"/>
</StackLayout>
uj5u.com熱心網友回復:
第一:要顯示此串列,您需要使用 a ListView(在性能問題上更好);
第二:條目可能是一個SearchBar.
所以,你可以做什么:
- 創建一個searchBar,用戶會在上面輸入一些資料。
- 當用戶輸入時,您的代碼將過濾串列,并且只會顯示與輸入匹配的內容(如您所提到的)。
在此鏈接中,它逐步顯示了如何實作它。所以也許你會改變你的代碼中的一些東西,但結果是專業的。
PS:嘗試僅按照此鏈接進行操作。如果有任何疑問,請用您所做的更新您的問題,我們將幫助您。玩得開心。
uj5u.com熱心網友回復:
您可以使用資料系結和 collectionview/listview,將 ItemsSource 設定為您的預測串列,然后在 locationText_Changed 方法中更改 itemsSourece。例如:
private async void locationText_Changed(object sender, TextChangedEventArgs e)
{
if (location == null)
{
await GetLocation();
}
string formattedLocation = string.Format("{0},{1}", location.Latitude, location.Longitude);
List<Prediction> predictionList = await VenueLogic1.GetVenues1(e.NewTextValue, formattedLocation);
var newlist=from n in predictionList where n.contains(text)
select n;
mycollectionlist.ItemsSource=newlist;}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/312908.html
標籤:xml 用户界面 xamarin.forms 数据绑定
上一篇:懸停效果的影像不會保持可見
下一篇:從GUI滑塊獲取可變浮點值
