对于一个项目,我使用一个非常简单的进度覆盖。
它只显示一个小块前进栏和覆盖屏幕。
所以在我的ShellView里
<Border Grid.Row="0"
Grid.RowSpan="11"
Grid.Column="0"
Grid.ColumnSpan="11"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Panel.ZIndex="3"
Background="#9E000000"
BorderBrush="Black"
BorderThickness="3"
Visibility="{Binding IsProgressing,
Converter={StaticResource BoolToVisibility}}">
<!-- omitted progressbar, text etc -->
</Border>我有一个非常简单的事件,它只设置可见性(IsProgressing)绑定和一些要显示的文本。
每当我想要有一个进度条时,我只要发布这个事件,就像
_eventAggregator.Publish(new ProgressingChange(true, "Loading ..."));到目前为止,除了一种情况外,这是非常有效的:
对于应用程序,我使用事件来导航屏幕。
所以我发表的另一个事件是:
_eventAggregator.Publish(new NavigationEvent(typeof(TargetViewModel)));它只设置目标屏幕:
public void Handle(NavigationEvent navigate)
{
var target = _screenFactory.FromType(navigate.TargetScreen);
this.ActivateItem(target);
}我的一个屏幕有很多项目,需要大约3秒的时间来加载。
因此,我想显示我的进步覆盖时,屏幕正在加载。
这就是不起作用的地方。当这些事件组合在一起时,新的屏幕和覆盖将同时显示。
这是:
_eventAggregator.Publish(new ProgressingChange(true, "Loading ..."));
_eventAggregator.Publish(new NavigationEvent(typeof(LongLoadingViewModel)));由于调试的原因,我没有禁用正在发生的正在进行的覆盖。
因此,屏幕被加载,屏幕上没有任何显示,大约3秒,然后进步覆盖和新的屏幕都显示。
我试过了
我遗漏了什么?
这里发生了什么事?
我怎么才能让它起作用?
-编辑-
下面是我的Handler方法的代码:
public void Handle(ProgressingChange progressing)
{
this.IsProgressing= progressing.IsProgressing;
this.ProgressingText= progressing.ProgressingText;
NotifyOfPropertyChange(() => IsProgressing);
NotifyOfPropertyChange(() => ProgressingText);
// of course, there is Notify in the setters themselves, too
}我使用了上面链接的源代码中的代码来强制用户界面更新,但这是行不通的。
void AllowUIToUpdate() {
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate(object parameter)
{
frame.Continue = false;
return null;
}), null);
Dispatcher.PushFrame(frame);
}此外,我尝试在关键部分发布,强制第一个发布在第二个发布之前执行,但这也不起作用。
-代码,至少显示进度覆盖
_eventAggregator.Publish(new ProgressingChange(true, "Activating ..."));
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => _eventAggregator.Publish(new NavigationEvent(typeof(LongLoadingViewModel)))), DispatcherPriority.ContextIdle, null);发布于 2014-10-02 10:16:31
这可能是一次黑客攻击,但您可以先尝试等待在发布导航事件之前呈现边框(波尔图栏)。为此,您可能可以在UI线程不再繁忙时调整这里给出的解决方案以执行某些代码(请参阅链接以获得完整的解释):
Dispatcher.BeginInvoke(new Action(() => Trace.WriteLine("DONE!", "Rendering")), DispatcherPriority.ContextIdle, null);如果这是可行的,那么至少您有一些东西可以开始使代码更清晰一些。
https://stackoverflow.com/questions/26157992
复制相似问题