0

i have an Azure Table that has 4 columns

 public class CategoryTable : TableEntity
{
    public bool IsChecked { get; set; }

    public string IconUrl { get; set; }

    public string IconActiveUrl { get; set; }

    public string CategoryName { get; set; }
}

when i try to get these values from table storage and populate my xamarin control the control remains empty.

    public async Task<List<Category>> GetCategories()
    {
        var results = new List<Category>();
        try
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(GlobalSetting.TableStorageConnection);

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            TableQuery<CategoryTable> query = new TableQuery<CategoryTable>();

            CloudTable table = tableClient.GetTableReference("Categories");
             var entities = await table.ExecuteQuerySegmentedAsync(query, null);

            //foreach (var item in entities)
            //{
            //    results.Add(new Category(item.IsChecked, item.IconUrl.Trim(), item.IconActiveUrl.Trim(), item.CategoryName.Trim())
            //    {

            //    });
            //}
            results = new List<Category>
            {
                new Category(false, "https://xxxx.blob.core.windows.net/icons/Jewllery_Gray.svg", "https://xxxx.blob.core.windows.net/icons/Jewllery_Green.svg", "Jewelry"),
                new Category(false, "https://xxxx.blob.core.windows.net/icons/Restaurant_Gray.svg", "https://xxxx.blob.core.windows.net/icons/Restaurant_Green.svg" , "Restaurant"),
                new Category(false, "https://xxxx.blob.core.windows.net/icons/WomenDresses_Gray.svg", "https://xxxx.blob.core.windows.net/icons/WomenDresses_Green.svg", "Women Dresses"),
                new Category(false, "https://xxxx.blob.core.windows.net/icons/BeautyProducts_Gray.svg" , "https://xxxx.blob.core.windows.net/icons/BeautyProducts_Green.svg", "Beauty Products"),
                new Category(false,  "https://xxxx.blob.core.windows.net/icons/AutoParts_Gray.svg",  "https://xxxx.blob.core.windows.net/icons/AutoParts_Green.svg" , "Auto Parts"),
                new Category(false, "https://xxxx.blob.core.windows.net/icons/Grocery_Gray.svg" ,  "https://xxxx.blob.core.windows.net/icons/Grocery_Green.svg" , "Grocery")
            };
        }
        catch (Exception ex)
        {

            throw;
        }

        return results;
    }

i cant even populate hard card coded values.

but if comment

        var entities = await table.ExecuteQuerySegmentedAsync(query, null);

i am able to return the hard coded values and they show up in my control.

the ExecuteQuerySegmentedAsync returns proper result though. eventually i want to use the values returned by exe command. but using this line of a code does not populate any value.

xamarin custom control is hooked up like this

    <controls:CategoriesControl
                        Margin="20, 0"
                        Grid.Row="2"
                        Grid.RowSpan="2"
                        Categories="{Binding Categories}"
                        Padding="0"
                        CategoriesSearch="{Binding CategoriesSearch, Mode=TwoWay}"
                        CategoryOne="{Binding CategoryOne, Mode=TwoWay}"
                        CategoryTwo="{Binding CategoryTwo, Mode=TwoWay}"
                        VerticalOptions="Center" />

GetCategories is called from another call in constructor

 private async Task GetCategories()
    {
        _originalCategories = (await _requestService.GetCategories()).ToList();

        foreach (var tag in _originalCategories)
            Categories.Add(new Category(false, tag.IconUrl, tag.IconActiveUrl, tag.CategoryName));

        // RaisePropertyChanged(nameof(Categories));
    }

Categories = new ObservableCollection<Category>();

please help.

Update summing it up; if i run ExecuteQuerySegmentedAsync command i get the proper result in entities collection. i add them to result collection and resturn but nothing gets populated. if i return hard coded values nothing gets populated. but if i comment the ExecuteQuerySegmentedAsync call and return hard coded values (offcourse when the exe call is commented out i cannot use entities object) i see my CategoriesControl populated. so problem is that if it makes a exe call control doesnt populate but if i do not make exe call control does populates.

Raas Masood
  • 1,475
  • 3
  • 23
  • 61
  • @Rass, According to your description, you get list data from Azure table, but don't populate CategoriesControl, am I right? I have saw you get data into results or Categories, please check if there are data in these list firstly, if yes, there are issue for CategoriesControl binding, what is CategoriesControl, can you provide one demo that can reproduce your issue here? Here is the article about populating azure table data:https://luisbeltran.mx/2019/02/02/azure-table-storage-with-xamarin-forms/ – Cherry Bu - MSFT Aug 28 '19 at 03:10
  • apologies for late reply. if i run ExecuteQuerySegmentedAsync command i get the proper result in entities collection. i add them to result collection and resturn but nothing gets populated. if i return hard coded values nothing gets populated. but if i comment the ExecuteQuerySegmentedAsync call and return hard coded values (offcourse when the exe call is commented out i cannot use entities object) i see my CategoriesControl populated. so problem is that if it makes a exe call control doesnt populate but if it does not make exe call control does populates. – Raas Masood Aug 29 '19 at 20:43

0 Answers0