提高WPF性能

在此同时求点击:点击点击点击。。。


  原文地址:http://www.wpftutorial.net/10PerformanceTips.html

Windows Presentation Foundation provides a very confortable way to developrich user experiences. A drop shadow for example can added by inserting twosimple lines of XML. But this simplicity can also mislead us to overuse them.This leads to performance issues. The following tipps may help you to avoid orfix them.

WPF 让我们很容易的开发富用户体验的程序。比如阴影效果可以用两行XML代码实现。但这可能会误导我们过度使用他们,而导致性能问题,下面有些Tips可以帮我们改善WPF程序性能。

Dispatch expensive calls either within the UI thread with a lowerDispatcherPriority by callingDispatcher.BeginInvoke() or to a background threadby using a BackgroundWorker to keep the UI responsive.

  当程序需要长时间进行后台操作的时候,使用Dispatcher.BeginInvoke()保持程序响应。

Fix binding errors because they consume a lot of time, trying to resolvethe path error, including searching for attached properties. You can find themby looking for System.Windows.Data Error in the Visual Studio output log.

  修复binding错误。binding上的错误会消耗很多时间,程序会试图解决path的错误,包括查找附加属性。你可以通过ststem.windows.data.error找到binding错误

Reduce the number of visuals by removing unneeded elements, combininglayout panels and simplifying templates. This keeps the memory footprint smalland improves the rendering performance.

  通过移出不必要的元素,合并layout panels,简化templates来减少可视化树的层次。这可以保证第内存使用,而改变渲染性能。

Prevent Software Rendering. The use of transparent windows by settingAllowsTransparency to true or using old BitmapEffects can cause WPF to renderthe UI in software on Windows XP, which is much slower.

  避免使用软件渲染。设定WindowsAllowsTransparencytrue或者使用老的BitmapEffects可以导致WPF使用软件渲染UI从而导致程序变慢。

Load resources when needed. Even thow it's the most comfortable way tomerge all resources on application level it can also cost performance byloading all resources at startup. A better approach is to load only often usedresources and load the other on view level.

  将资源定义在使用的地方。虽然把所有资源放到应用程序级很方便,但这样会迫使程序在开始时加载所有资源。更好的办法是在用到的地方加载。

Virtualize lists and views by using a VirtualizingStackPanel as ItemsPanelfor lists. This only creates the visible elements at load time. All otherelements are lazy created when they get visible. Be aware that grouping orCanContextScrol="True" prevents virtualization!

  使用VirtualizingStackPanel 虚拟化列表作为lists中的ItemsPanel和视图.VirtualizingStackPanel只会在lists中的item可见时加载。但注意要分组和设定CanContextScrolTrue可以组织虚拟化。

Enable Container Recycling. Virtualization brings a lot of performanceimprovements, but the containers will be disposed and re created, this is thedefault. But you can gain more performance by recycle containers by settingVirtualizingStackPanel.VirtualizationMode="Recycling"

  虚拟话可以带来很大的性能提升,但是默认情况下容器会被重新创建。我们可以通过设定VirtualizingStackPanel.VirtualizationMode="Recycling" 来得到更多的性能提升。

Freeze Freezables by calling Freeze() in code orPresentationOptions:Freeze="true" in XAML. This reduces memoryconsumption and improves performance, because the system don't need to monitorfor changes.

  通过在代码中调用Freeze()或者在Xmal中设定PresentationOptions:Freeze="true"来冻结可以冻结的控件。由于这样系统不必监听该控件的变化,所以可以带来性能的提升

Disable Assembly localization if you don't need it. By using the[NeutralResourcesLanguageAttribute].This prevents an expensive lookup forsatelite assemblies

  不太理解……高手可以帮忙翻译

Lower the framerate of animations by setting Storyboard.DesiredFrameRateto lower the CPU load. The default is 60 frames/second

  降低动画的帧率。大多数动画不需要高帧率,而系统默认为60frames/sec,所以可以设定Storyboard.DesiredFrameRate为更低值。

Use StreamGeometries instead of PathGeometries if possible to draw complex2D geometries, because they are much more efficient and consume less memory.

  尽可能使用StreamGeometries 代替PathGeometries ,因为它可以一低内存占用,更高效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值