[英]Show specific data from a selected item in a listview (xamarin form)
我正在使用xamarin表單開發移動應用程序,在“ user_page”中,我在ListView中顯示了用戶的最后順序,並且我添加了選擇特定順序以獲取有關它的更多信息的可能性。
這是我的xaml代碼:
<ListView x:Name="Wash_list">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnMore"
CommandParameter="{Binding .}"
Text="More Info" />
<MenuItem Clicked="OnQR"
CommandParameter="{Binding .}"
Text="QR_Code" />
<!--IsDestructive="True"-->
</ViewCell.ContextActions>
<StackLayout Padding="15,0">
<Label Text="{Binding washType}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
這是我的C#代碼(我被卡在上面了。):
async public void OnMore(object sender, EventArgs e)
{
int i = 0;
HttpClient _Client = new HttpClient();
var content = await _Client.GetStringAsync(urlTrade);
var get = JsonConvert.DeserializeObject<List<WashBuyData>>(content);
var mi = ((MenuItem)sender);
for (i = 0; i <= get.Count ; i++)
if (true)
await DisplayAlert("About " + mi.CommandParameter, "Buy on: " + get[i].timestamp, "OK");
}
所以...我想做的是顯示所選項目中的特定信息,我該怎么做? 我試圖從所選項目中選擇文本值或ID來設置我的“ i”參數,但沒有成功...
因此,在您的ListView中添加ItemTapped="OnItemTapped"
<ListView x:Name="Wash_list"
ItemTapped="OnItemTapped">
之后,添加CodeBehind。
void OnItemTapped(Object sender, ItemTappedEventArgs e)
{
var dataItem = (YourModel)(e.Item);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.