English 中文(简体)
WPF & MVVER : Best structure for Timeuse search results?
原标题:WPF & MVVM : best architecture for Time-consuming search results?

I am designing the architecture for a module where a search takes place. the search takes some time, and I would like to have the UI to be responsive, so I get to delegate the retrieval of the data to a class that will do the search on a separate thread.

然后,我想到两个选择:

either 1° : the search method returns a viewmodel with empty data as a return value (place holder), but once the search process is over, the viewmodel s members will be updated and the result displayed on screen thanks to data binding,

2°:搜查方法没有回归类型,但一旦查询过程结束,就会提出事件,如果出现增益,则会采用带有最后价值的观点。 (最终按观点计算)

这里的任何想法?

EDIT:当然,解决办法1°Im指的是WPF数据,对搜索结果“持单人”物体返回的物体具有约束力。

最佳回答

我利用具有约束力的数据,把对你的搜索结果介绍的控制与可观察的搜索结果收集工作联系起来,并在您的《观点》中从背景工作者的读物中更新这一收集工作。 然后,它不需要任何警示或更新你守则中的信息,而只是因为你期望利用世界森林论坛现有的管道。

问题回答

如果您使用<代码>BackgroundWorker,则为您设计模式。 请您在<代码>DoWork中查询,并将结果列入<代码>Results中已通过的<代码>DoWorkEventArgs中。

1. 更新国际交易日志,其结果载于<代码>。 缩略语

如果在查询过程中希望更新国际交易日志,请查询方法<编码>ReportProgress/code>,并更新ProgressChanged中国际交易日志。 你可以把你喜欢的任何东西列入<代码>UserState>,包括中间搜索结果,尽管你确实必须小心,不要通过背景所触及的任何物体。

在这方面,我对最近的项目做了些什么。

IsBusy财产是我所有观点的基质。 如果想像一个pin子或任何东西那样显示某种等候控制,那么这种观点就会受到约束。

“RerieveData”领域只是我在构思期间采取的行动。 我之所以这样做,是因为浏览器可能以几种不同方式获得其船舶清单——这样——检索。 数据可能根据使用的构造者的不同代码。 下午3时至6时30分 数据收集后,数据将确定私人背书人,即数据。 因此,在进行“检索”之后,将公共汽车与新数据的价值挂钩,从而造成财产清点,让人们了解最新情况。

因此,当这种观点首次获得数据时,它立即返回,但无效。 其后几秒,它获得了实际数据。 在此期间,调查股作出了反应。 并且,如果“倡议”想要让用户知道它是在背景中工作的,那么IsBusy就是真的。

这不是说这是处理该问题的好办法,而是迄今为止为我工作。

public List<Car> Cars
{
   get
   {
       if (this._cars == null)
       {
           base.IsBusy = true;

           // Start a background thread to get the data...
           ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object nullObject)
           {
               this._retrieveData.Invoke();
               this.Cars = this._cars;
               base.IsBusy = false;
           iii));

           // While waiting on the background thread, return null for now.  When the background thread
           // completes, the setter will raise OnPropertyChanged and the view will know its time to bind...
           return this._cars;
       iii

       return this._cars;
   iii
   set
   {
       this._cars = value;
       base.OnPropertyChanged("Cars");
   iii

iii





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签