当前位置: 首页 > 知识库问答 >
问题:

Xaml在设置Listview后分配额外的类

云和同
2023-03-14

以下是模型:https://github.com/xiaofaye/woocommerce.net/blob/master/woocommerce/v3/product.cs#L503

当生成列表时,我将迭代产品类。但是,图像存储在不同的模型中,我不知道如何在listview已经设置好之后调用Xaml的另一个类。

我只需要一个图像来传递我知道产品模型有一个列表称为图像,但我不知道如何将列表传递到图像源绑定


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Ecombeta.Views.Products"
             Title="Productsold"
             BackgroundColor="#c4c3c0">

    <ContentPage.Content>
        <StackLayout>

            <ListView x:Name="productsListView"
                      HasUnevenRows="True"                       
                  VerticalOptions="FillAndExpand"
                      SeparatorVisibility="None">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                <Frame HasShadow="True" Margin="8">
                                    <StackLayout>
                                        <Label x:Name="something" Text="{Binding name}" FontSize="Large"/>
                                        <Image Source="{Binding     }"/>
                                        <Label Text="{Binding date_created, StringFormat='{0:dd/MM/yyyy}'}" FontSize="Small" FontAttributes="Italic"/>
                                        <Label Text="{Binding price }"/>
                                        <Label Text="{x:Binding enable_html_description  }" FontSize="Medium"/>
                                        <Label Text="{x:Binding sku}" FontSize="Medium"/>
                                        <Button BindingContext="{Binding id}" Clicked="ProductClicked"></Button>
                                    </StackLayout>
                                </Frame>

                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

        </StackLayout>
    </ContentPage.Content>
</ContentPage>

后端

 public Products()
        {
            InitializeComponent();



            InitAsync();



        }
        private async void Back_Clicked(object sender, EventArgs e)
        {
            await Navigation.PopAsync();
        }



        private async Task InitAsync()
        {



            RestAPI rest = new RestAPI("http://example.co.za/wp-json/wc/v3/", "CK_XXXXXX", "cs_xXXXXX");
                WCObject wc = new WCObject(rest);
            var products = await wc.Product.GetAll();
            var p = await wc.Product.GetAll(new Dictionary<string, string>() {
                    {"tag", Suppliers.tagid },
                    { "per_page", "80" } }); ;

            List<ProductImage> z = new List<string> { p.images };
            productsListView.ItemsSource = p;

        }

        async void ProductClicked(object sender, EventArgs args)
        {





            var btn = (Button)sender;

           var a = btn.BindingContext;

            Orders.singleID = Convert.ToInt32(a);




           await Navigation.PushAsync(new Orders());

共有1个答案

景正文
2023-03-14

我没有办法做到这一点,确切的事情我当时想要的。

简而言之,问题是产品有一个Image[]作为示例,我需要访问

Product image[].src所以在绑定中,我最后说


  var p = await wc.Product.GetAll(new Dictionary<string, string>() {
                    {"tag", Suppliers.tagid },
                    { "per_page", "80" } }); ;



  foreach (var item in p)
            {
                foreach (var z in item.images)
                {
                    if (item.images != null)
                    {
                        var YourBinding = z.src;
                    }
                }
            }

//There is more then likely a better way to go about it but its how I ended up sorting the problem for one of the Pull Methods of mine
 类似资料:
  • 在我的活动中,我有一个listview和一个按钮。每一个都有各自的目的。 我的listview显示另一个活动中的项目详细信息。 问题是如何在相同的活动中为按钮实现onClickListener?

  • 我有以下代码: MainWindow.xaml Employee.cs 这是非常简单的代码,我只想将我的 Employee.cs 类中的 和 属性绑定到 MainWindow.xaml 中文本框的文本属性,但在运行代码时,这些文本框中没有出现任何内容。绑定正确吗?

  • 我们可通过quota来设置磁盘的配额,限定某个用户只能使用有限的硬盘空间,这在文件服务器和邮件服务器上是很常用的。Linux通过quota程序支持磁盘配额,它以分区(partition)为单位进行设置的。设置步骤如下: 确定内核支持quota功能,然后下载安装quota程序。 debian:~# apt-get install quota 修改/etc/fstab文件,在分区上启用quota功

  • 本文向大家介绍xaml 安装或设置,包括了xaml 安装或设置的使用技巧和注意事项,需要的朋友参考一下 示例 编写第一个XAML的最简单方法是安装Microsoft Visual Studio。它可以从Microsoft免费获得。 安装后,您可以使用VB.NET或C#代码创建WPF应用程序类型的新项目。 从某种意义上说,这与Windows窗体相似,因为您拥有一系列窗口,主要区别在于这些窗口是用XA

  • 更改Queue的属性 方法参数SetQueueAttributeRequest queueName : String : required 更改属性的Queue的名称 queueAttribute : QueueAttribute : optional 设置的Queue的属性,具体字段的含义请参见createQueue()中的解释 对于用户自定义属性userAttributes中的每个keyVal

  • 我在listview上体验过平滑滚动的奇怪行为。我的清单上有30个项目。当我平滑滚动通过 在屏幕的末尾会有一些额外的空间。实际上listview上移了一点。图片附后。但是如果我手动滚动,就没有空间了。如何解决这种行为? 这是我的布局: