///
/// 显示正在执行结果界面
///
/// 执行结果界面提示文字
private void ShowDialog(string resultText)
{
gridDialog.Visibility = System.Windows.Visibility.Visible;
borderShadow.Visibility = System.Windows.Visibility.Visible;
gridResult.Visibility = System.Windows.Visibility.Visible;
loading.Visibility = System.Windows.Visibility.Hidden;
textBlockDisplay.Text = resultText;
//计算位置使显示居中
gridDialog.Margin = new Thickness(0, scrollViewer1.VerticalOffset-50, 0, 0);//scrollViewer1.VerticalOffset为滚动过的位置
gridDialog.Height = scrollViewer1.ViewportHeight+100;
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1d);
timer.Tick += (sender, e) =>
{
gridDialog.Visibility = System.Windows.Visibility.Hidden;
};
timer.Start();
}
//PS:由于使用到了滚动条所以才有了 设置高度的 那个动作 这个看实际需求来进行修改
调用:
TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext();
CancellationToken token = new CancellationToken();
Task.Factory.StartNew(new Action(() =>
{
//里面写你的实际需求 如导出Excel的代码
})).ContinueWith(w => { ShowDialog("导出Excel成功!"); }, token, TaskContinuationOptions.None, scheduler);
//PS:调用中使用到了线程中的异步操作 这部分不是很懂 调用的片段可以放到 按钮触发事件