gpt4 book ai didi

c# - TreeViewItem 无法在 BackgroundWorker 中更新

转载 作者:行者123 更新时间:2023-11-30 18:02:47 26 4
gpt4 key购买 nike

我有这个方法来更新我的 TreeView。如果我不使用 BackgroundWorker 一切正常。但如果这样做,那么我的 TreeViewItem 不会更新,但它是 DataContex 的变化。这也很好用:item.IsEnabled = false;

private void twSports_Expanded(object sender, RoutedEventArgs e)    
{
TreeViewItem item = e.OriginalSource as TreeViewItem;
TreeLeaf leaf = item.DataContext as TreeLeaf; var bgWorker = new BackgroundWorkerOnGrid(gridPartitions);
bgWorker.DoWork += delegate(object s, DoWorkEventArgs args)
{
if (leaf.Item != null)
{
if (leaf.Item.GetType() == typeof(SportType))
{
SportType sport = leaf.Item as SportType;
args.Result = LoadSportPartitions(sport);
}
if (leaf.Item.GetType() == typeof(SportPartition))
{
SportPartition partition = leaf.Item as SportPartition;
args.Result = LoadSportPartitions(partition);
}
}
};

bgWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
List<SportPartition> partitions = args.Result as List<SportPartition>;

if (partitions != null)
{
leaf.LoadChilds(partitions.ToArray()); //it doesn't work
item.IsEnabled = false; //it works
}

(s as BackgroundWorkerOnGrid).Dispose();
};

bgWorker.RunWorkerAsync(leaf.Item);}

有什么想法吗?

最佳答案

关于c# - TreeViewItem 无法在 BackgroundWorker 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7900624/

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