Hi i'm trying to pull a single product instead of multiple I found the Wrapper WoocomNet has a get instead of GetAll method so I'm passing the ID and trying to load it im getting the correct id but cant load it into my listview Going to Show my Code the XAML and The Wrapper Method
async void ProductClicked(object sender, EventArgs args)
{
var btn = (Button)sender;
var productid = btn.BindingContext;
RestAPI rest = new RestAPI("site.com/wp-json/wc/v3/""key""secret")
WCObject wc = new WCObject(rest);
var p = await wc.Product.Get(Convert.ToInt32(productid));
productsListView.ItemsSource = p;
}
Xaml
<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 ProductImage.src}"/>
<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>
Wrapper
namespace WooCommerceNET.Base
{
public class WCItem<T>
{
public WCItem(RestAPI api);
public string APIEndpoint { get; protected set; }
public RestAPI API { get; protected set; }
[AsyncStateMachine(typeof(WCItem<>.<Add>d__12))]
public Task<T> Add(T item, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<AddRange>d__13))]
public Task<BatchObject<T>> AddRange(BatchObject<T> items, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<Delete>d__17))]
public Task<T> Delete(int id, bool force = false, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<DeleteRange>d__18))]
public Task<string> DeleteRange(BatchObject<T> items, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<Get>d__9))]
public Task<T> Get(int id, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<Get>d__10))]
public Task<T> Get(string email, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<GetAll>d__11))]
public Task<List<T>> GetAll(Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<Update>d__14))]
public Task<T> Update(int id, T item, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<UpdateRange>d__16))]
public Task<BatchObject<T>> UpdateRange(BatchObject<T> items, Dictionary<string, string> parms = null);
[AsyncStateMachine(typeof(WCItem<>.<UpdateWithNull>d__15))]
public Task<T> UpdateWithNull(int id, object item, Dictionary<string, string> parms = null);
}
}
My Error code:Severity Code Description Project File Line Suppression State Suppression State Error CS0266 Cannot implicitly convert type 'WooCommerceNET.WooCommerce.v3.Product' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?) Ecombeta \Products.xaml.cs 68 Active
I just need productlistview's source to be set to p But i'm not sure how these cast's work
If anyone would borrow a minute i'd really appreciate it.
Thank you
Also for Ref going to show the get all way
private async Task InitAsync()
{
RestAPI rest = new RestAPI("http://example.com/wp-json/wc/v3/", "ck_xxxx", "cs_xxxxxxx");
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" } }); ;
productsListView.ItemsSource = p;
}
The ItemsSource
can only set to an IEnumerable
, i.e. you have to create a collection of products:
productsListView.ItemsSource = new Product[1] { p };
Эта статья взята из Интернета, укажите источник при перепечатке.
Если есть какие-либо нарушения, пожалуйста, свяжитесь с[email protected] Удалить.
я говорю два предложения