是否可以在WPF分页期间调用UpdateLayout? [英] Is there a way around calling UpdateLayout during WPF Pagination of controls?

查看:118
本文介绍了是否可以在WPF分页期间调用UpdateLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用WPF控件进行大量自定义报告,以布局和打印报告.它可以正常工作并生成漂亮的报告,但是我在生成报告所需的时间上存在问题.我正在迭代地将项目添加到ObservableCollection 然后检查它是否仍然适合页面.理想情况下,我将能够在控件上调用Measure()并获取更新的DesiredSize,但看来直到Measure和UpdateLayout都被使用,控件才处理更新的集合数据. 叫.作为一个粗略的数量级,对于4页的报告,执行Measure大约需要5毫秒,执行UpdateLayout大约需要1.5秒.当我开始进入30多页的报告时,此方法非常慢,而且效果不是很好 用户体验.

I have been doing lots of custom reports using WPF controls to layout and print the report. It works fine and generates nice looking reports, but I am having an issue with the time it takes to generate the report. I am iteratively adding items to an ObservableCollection and then checking if it still fits on the page. Ideally I would be able to call Measure() on the control and get the updated DesiredSize, but it appears that the control doesn't handle the updated collection data until Measure and UpdateLayout are called. As a rough order of magnitude, Measure takes about 5ms to execute and UpdateLayout takes about 1.5 seconds to execute for a 4 page report. When I start getting up into the 30+ page reports this method is terribly slow and is not making a very good user experience.

我确信我可以做些事情以减少填充页面所需的迭代次数.我不是在寻找那种性质的解决方案.我想知道的是,是否有一种方法可以让控件的DesiredSize反映绑定的数据而无需 反复调用UpdateLayout?

I am sure I can do things to reduce the number of iterations I need to do to fill a page. I am not looking for solutions of that nature. What I would like to know is if there is a way to get the control's DesiredSize to reflect the bound data without having to repeatedly call UpdateLayout?

谢谢

推荐答案

请检查以下内容:http://stackoverflow.com/questions/9519295/updatelayout-on-wpf-click

例如:

private void button1_Click(object sender, RoutedEventArgs e)
   {
       label1.Content = "Button 1 Clicked";
       label1.UpdateLayout();
       ForceUIToUpdate();
       Thread.Sleep(4000);
       label1.Content = "button 1 Updated";
   }


public static void ForceUIToUpdate()
   {
       DispatcherFrame frame = new DispatcherFrame();
       Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Render, new     DespatcherOperationCallback(delegate(object parameter)
       {
           frame.Continue = false;
           return null;
       }), null);
       Dispatcher.PushFrame(frame);
   }


这篇关于是否可以在WPF分页期间调用UpdateLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆