Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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# 围绕数据对象加载设置IsBusy标志_C#_Wpf - Fatal编程技术网

C# 围绕数据对象加载设置IsBusy标志

C# 围绕数据对象加载设置IsBusy标志,c#,wpf,C#,Wpf,我们有一个相对较大的数据模型类DataModel,它绑定到各种UI控件。我们希望在加载数据模型实例时显示WPF Toolkit Extended中的忙碌指示器 下面是示例代码。当LoadReport函数执行时,busy指示器显示,但在assign语句之后,当绑定操作仍在处理时,即在接口“就绪”之前,busy指示器消失。我们能做些什么来等这个吗 // Show we are busy. this.Dispatcher.Invoke(DispatcherPriority.Send, (Action)

我们有一个相对较大的数据模型类
DataModel
,它绑定到各种UI控件。我们希望在加载数据模型实例时显示WPF Toolkit Extended中的忙碌指示器

下面是示例代码。当
LoadReport
函数执行时,busy指示器显示,但在assign语句之后,当绑定操作仍在处理时,即在接口“就绪”之前,busy指示器消失。我们能做些什么来等这个吗

// Show we are busy.
this.Dispatcher.Invoke(DispatcherPriority.Send, (Action)delegate()
{
    this.BusyMessage = "Loading report...";
    this.IsBusy = true;
});

var instance = this.LoadReport();
this.DataModel = instance;

// Show we are no longer busy.
this.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
    this.BusyMessage = null;
    this.IsBusy = false;
});


<toolkit:BusyIndicator IsBusy="{Binding ThisScreen.IsBusy}" BusyContent="{Binding ThisScreen.BusyMessage, TargetNullValue='Please wait...'}" >
    <Grid x:Name="ScreenGrid" />
</toolkit:BusyIndicator>
//显示我们很忙。
this.Dispatcher.Invoke(DispatcherPriority.Send,(Action)delegate()
{
this.BusyMessage=“加载报告…”;
this.IsBusy=true;
});
var instance=this.LoadReport();
this.DataModel=instance;
//显示我们不再忙碌。
this.Dispatcher.Invoke(DispatcherPriority.Background,(Action)delegate()
{
this.BusyMessage=null;
this.IsBusy=false;
});

这似乎不是一个不寻常的问题,但我没有任何运气寻找解决方案。。。提前谢谢。

我想说这是意料之中的行为

LoadReport()
方法完成后,立即将
BusyMessage
设置为null,将
IsBusy
设置为false。这使得UI的其余部分没有时间首先更新

更好的解决方案可能是引发
LoadComplete
事件并放置

// Show we are no longer busy.
this.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
    this.BusyMessage = null;
    this.IsBusy = false;
});
在处理程序中:


这将为其他绑定提供更新时间—尽管不能保证它们会首先启动。

也许您可以尝试将
BusyMessage
&
IsBusy
设置为内联,而不是通过调度程序调用

this.DataModel = instance;  

// set these directly
this.BusyMessage = null;     
this.IsBusy = false;
这将通知用户界面,在数据模型绑定发生的同时,您不再忙了——一切都将立即发生


使用Dispatcher类似于将通知直接推送到UI线程中。您的忙碌状态与您所做的其他绑定和UI更改“未链接”。

我确实了解原因,但无法知道绑定处理何时完成?@dythim-我不这么认为,除非您在每个属性的
get
中放入一些代码,以便知道何时调用了它。不幸的是,出于同样的原因,这将不起作用。绑定更新发生在后台线程中,而不是内联线程中。@dythim我没有尝试过,但我会尝试:)下一步我会尝试的可能是在设置
IsBusy
false之前进行黑客
Sleep
。。。但这只是因为我自己也有这个“渲染速度慢”的问题。尝试使用.NET4.0-它在呈现UI时比3.5快得多。