[英]How to bind to a property of a list in a Listview
I'm trying to pull the image i'm going to show the structure could anyone explain how I could bind to it?我正在尝试拉图像我要展示结构 谁能解释我如何绑定到它?
What I have tried is saying Binding: images[5];
我试过的是说
Binding: images[5];
Any Idea's?有任何想法吗?
I wanted to simply just bind to featured_src but its not part of the wrapper, It doesn't return along with the json In the C# application but on the postman response I do get the Featured_src (Featured Image)我只想绑定到 features_src 但它不是包装器的一部分,它不会与 json 一起返回在 C# 应用程序中,但在邮递员响应中我确实得到了 Featured_src(特色图像)
Method方法
RestAPI rest = new RestAPI("http://azipit.co.za/mica-market-app/wp-json/wc/v3/", "ck_0112f135e2f9b32cc147f28028fd621f919bc890", "cs_38ea21f4d63eb96a801868993b66065dcb0362fa");
WCObject wc = new WCObject(rest);
var p = await wc.Product.GetAll(new Dictionary<string, string>() {
{"tag", Suppliers.tagid },
{ "per_page", "80" } }); ;
productsListView.ItemsSource = p;
Response回复
Screens to make it easier:屏幕使其更容易:
The class:班上:
[DataContract]
public class Product : JsonObject
{
public Product();
public static string Endpoint { get; }
[DataMember(EmitDefaultValue = false)]
public bool? shipping_required { get; set; }
[DataMember(EmitDefaultValue = false)]
public ProductDimension dimensions { get; set; }
public decimal? weight { get; set; }
[DataMember(EmitDefaultValue = false)]
public bool? sold_individually { get; set; }
[DataMember(EmitDefaultValue = false)]
public bool? backordered { get; set; }
[DataMember(EmitDefaultValue = false)]
public bool? backorders_allowed { get; set; }
[DataMember(EmitDefaultValue = false)]
public string backorders { get; set; }
[DataMember(EmitDefaultValue = false)]
public string stock_status { get; set; }
public int? stock_quantity { get; set; }
[DataMember(EmitDefaultValue = false)]
public bool? manage_stock { get; set; }
[DataMember(EmitDefaultValue = false)]
public string tax_class { get; set; }
[DataMember(EmitDefaultValue = false)]
public string tax_status { get; set; }
[DataMember(EmitDefaultValue = false)]
public string button_text { get; set; }
[DataMember(EmitDefaultValue = false)]
public string external_url { get; set; }
[DataMember(EmitDefaultValue = false)]
public bool? shipping_taxable { get; set; }
[DataMember(EmitDefaultValue = false)]
public string shipping_class { get; set; }
[DataMember(EmitDefaultValue = false)]
public string shipping_class_id { get; set; }
[DataMember(EmitDefaultValue = false)]
public bool? reviews_allowed { get; set; }
[DataMember(EmitDefaultValue = false)]
public List<int> grouped_products { get; set; }
[DataMember(EmitDefaultValue = false)]
public List<int> variations { get; set; }
[DataMember(EmitDefaultValue = false)]
public List<ProductDefaultAttribute> default_attributes { get; set; }
[DataMember(EmitDefaultValue = false)]
public List<ProductAttributeLine> attributes { get; set; }
[DataMember(EmitDefaultValue = false)]
public List<ProductImage> images { get; set; }
[DataMember(EmitDefaultValue = false)]
public List<ProductTagLine> tags { get; set; }
Product Image Class:产品图片类别:
[DataContract]
public class ProductImage
{
public ProductImage();
[DataMember(EmitDefaultValue = false)]
public long? id { get; set; }
[DataMember(EmitDefaultValue = false)]
public DateTime? date_created { get; set; }
[DataMember(EmitDefaultValue = false)]
public DateTime? date_created_gmt { get; set; }
[DataMember(EmitDefaultValue = false)]
public DateTime? date_modified { get; set; }
[DataMember(EmitDefaultValue = false)]
public DateTime? date_modified_gmt { get; set; }
[DataMember(EmitDefaultValue = false)]
public string src { get; set; }
[DataMember(EmitDefaultValue = false)]
public string name { get; set; }
[DataMember(EmitDefaultValue = false)]
public string alt { get; set; }
}
<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 title}" FontSize="Large"/>
<Image Source="{Binding images[5]}"/>
<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"/>
<Label Text="{Binding type}" BindingContext="{Binding type}"/>
<Button BindingContext="{Binding id}" Clicked="ProductClicked"></Button>
</StackLayout>
</Frame>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Going to answer my own question.要回答我自己的问题。
Correct me if there are other ways or better ways but如果有其他方法或更好的方法,请纠正我,但是
Generally How I found the binding is by going down the local response.一般来说,我如何找到绑定是通过降低本地响应。
so in my case所以就我而言
p --> [0] --> images --> [0] --> src --> Magnifying glass to view --> Expression is your binding in my case again --> p[0].images[0].src p --> [0] --> 图像 --> [0] --> src --> 放大镜查看 --> 在我的情况下,表达式再次是你的绑定 --> p[0].images[0 ].src
So my Binding for image:所以我的图像绑定:
<Image Source="{Binding images[0].src}"/>
So I obviously just want the first image of every Product but this can be extended to any property I believe, So If I wanted to 3rd image of every product in the list所以我显然只想要每个产品的第一个图像,但这可以扩展到我相信的任何属性,所以如果我想要列表中每个产品的第三个图像
It would be这将是
<Image Source="{Binding images[2].src}"/>
Or if I wanted the id of every 1st image it would be或者,如果我想要每张图片的 ID,那就是
<Image Source="{Binding images[0].id}"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.