【问题标题】:Show specific data from a selected item in a listview (xamarin form)在列表视图中显示来自选定项目的特定数据(xamarin 表单)
【发布时间】:2018-03-29 19:26:48
【问题描述】:

我正在使用 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”参数,但没有成功......

【问题讨论】:

    标签: android xamarin xamarin.forms


    【解决方案1】:

    所以.. 在您的 ListView 中添加 ItemTapped="OnItemTapped"

    <ListView x:Name="Wash_list"
              ItemTapped="OnItemTapped">
    

    之后,添加 CodeBehind。

    void OnItemTapped(Object sender, ItemTappedEventArgs e)
    {
        var dataItem = (YourModel)(e.Item);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-14
      • 1970-01-01
      • 2013-01-05
      • 2016-01-03
      • 2015-12-15
      • 2015-04-22
      相关资源
      最近更新 更多