我有一个有 4 列的 Azure 表
public class CategoryTable : TableEntity
{
public bool IsChecked { get; set; }
public string IconUrl { get; set; }
public string IconActiveUrl { get; set; }
public string CategoryName { get; set; }
}
当我尝试从表存储中获取这些值并填充我的 xamarin 控件时,控件仍然为空。
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;
}
我什至无法填充硬卡编码值。
但如果评论
var entities = await table.ExecuteQuerySegmentedAsync(query, null);
我能够返回硬编码值,它们会显示在我的控制中。
ExecuteQuerySegmentedAsync 虽然返回正确的结果。最终我想使用 exe 命令返回的值。但是使用这行代码不会填充任何值。
xamarin 自定义控件是这样连接的
<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 从构造函数中的另一个调用中调用
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>();
请帮忙。
更新 总结一下;如果我运行 ExecuteQuerySegmentedAsync 命令,我会在实体集合中得到正确的结果。我将它们添加到结果集合并返回,但没有填充任何内容。如果我返回硬编码值,则不会填充任何内容。但是如果我评论 ExecuteQuerySegmentedAsync 调用并返回硬编码值(当然,当 exe 调用被注释掉时,我不能使用实体对象)我看到我的 CategoriesControl 已填充。所以问题是,如果它使 exe 调用控件不填充,但如果我不使 exe 调用控件填充。