Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在一个漫长的过程中产生使用_C#_Wpf - Fatal编程技术网

C# 在一个漫长的过程中产生使用

C# 在一个漫长的过程中产生使用,c#,wpf,C#,Wpf,假设我有一个函数 public IList<type> Fetch() { IList<type> list = new List<type>(); //here comes a really long process and an item gets added to the list every few seconds return list; } 上面的函数必须等待Fetch()函数返回一个值,但我希望在添加项

假设我有一个函数

public IList<type> Fetch()
{
       IList<type> list = new List<type>();
       //here comes a really long process and an item gets added to the list every few seconds
       return list;
}
上面的函数必须等待Fetch()函数返回一个值,但我希望在添加项时更新视图,因此我认为应该向该函数发送对databound属性的引用,例如,它看起来像:

Fetch(AnObjectThatHasADataboundProperty.ThatProperty);
  • 你会这样做吗
  • 我以前从未使用过
    yield
    ,这种情况下应该使用yield吗 被使用
每当集合发生更改时,您可以使用该类型直接进行视图更新。例如,当您使用MVVM时,您的视图模型可以公开一个可观察的集合,然后您可以从视图绑定到它


如果然后从某个地方更新集合,视图也会自动更新。

哪个GUI是WPF或WinForm使用ObservableCollection并绑定到它。@poke如果这样做,我仍然必须发送ObservableCollection属性作为对Fetch函数的引用,然后添加到它?@poke我不知道已经有这样一个类可用,谢谢。
Fetch(AnObjectThatHasADataboundProperty.ThatProperty);