gpt4 book ai didi

c# - 检查 gridView 是否为空

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:25 25 4
gpt4 key购买 nike

我想知道我的 gridView 是否为空 - 里面没有任何项目。我已尝试执行以下操作:

public sealed partial class Profile : Page
{
Boolean isGridViewEmpty = true;
}

这是显示 GridView 的函数,我试图让它也判断 GridView 是否为空

//gets the animals of the specific chosen user's data tabe
public async void getAnimalsData(int ownerId)
{
int count = 0;
regitration.getAnimalsOfUserTableResponseGetAnimalsOfUserTableResult r = await cal.getAnimalsOfUserTableAsync(ownerId);
List<Animal> theAnimalList = new List<Animal>();
Animal a = null;
XmlReader xr = r.Any1.CreateReader();
XmlDocument document = new XmlDocument();
document.Load(xr);
XmlNodeList theXmlList = document.GetElementsByTagName("Table");
foreach (XmlElement item in theXmlList)
{
a = new Animal();
foreach (XmlNode node in item.ChildNodes)
{
switch (node.Name)
{
case "animalId": a.AnimalId = int.Parse(node.InnerText); count++; break;
case "ownerId": a.OwnerId = int.Parse(node.InnerText); count++; break;
case "animalName": a.Animalname = node.InnerText; count++; break;
case "fur": a.Fur = node.InnerText; count++; break;
case "level": a.Level = int.Parse(node.InnerText); count++; break;
case "money": a.Money = int.Parse(node.InnerText); count++; break;
}
}
theAnimalList.Add(a);
}
grid2.ItemsSource = theAnimalList;
if (count == 0)
{
isGridViewEmpty = true;
}
else
{
isGridViewEmpty = false;
}

}

调试时,我可以看到它并没有真正退出该函数,但是,它也没有显示错误消息。它只是出现在最后一个花括号之后。我不知道我做错了什么,计数似乎工作正常,在调试时它还向我显示 isGridViewEmpty 确实设置为 true,但是每当我来实现该功能并检查如果 isGridViewEmpty 为真,则它不起作用。此外,正如我之前提到的,调试器卡在函数 getAnimalsData

最佳答案

getAnimalsData 函数是async。所以它确实有效,只是因为它发生在后台而不是我按下它的顺序,所以每当我有条件相关的功能时,它看起来没用。所以我把它变成了Task而不是 void 并将 await 放在函数之前。

更多细节可以引用Asynchronous programming with async and await (C#) .

关于c# - 检查 gridView 是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53704613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com