作者:Nasa 文章出处:我和未来有约会 (http://nasa.cnblogs.com/

性能优化

监视性能(FPS)【FPS(Frames Per Second):每秒传输帧数。】

Silverlight的呈现性能会因指定的宿主参数和内容的复杂程度而异。 为了监视FPS的值我们在开发的过程中将EnableFrameRateCounter的方法:

 

 1.在Object标签的属性里设置 ,增加EnableFrameRateCounter=true

 

  <div id="DownPanel">
<asp:Silverlight ID="Xaml1" runat="server" EnableFrameRateCounter="true" Source="ClientBin/LogSilverLight.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%" EnableGPUAcceleration="true" >
<PluginNotInstalledTemplate>
_</PluginNotInstalledTemplate>
</asp:Silverlight>
</div>

2.在cs代码中设置(个人觉得不太好控制)

 

System.Windows.Interop.SilverlightHost host = Application.Current.Host;
System.Windows.Interop.Settings settings = host.Settings;
settings.EnableFrameRateCounter = true;
settings.MaxFrameRate = 60;

性能优化注意的地方:

1.谨慎使用透明背景

Silverlight 插件使用透明背景会对性能产生很大影响,因此应尽可能避免使用此功能。例:

 

 

<param name="background" value="Transparent"/>     <param name="Windowless" value="true"/>

 

2.尽量使用各种加速与缓存

对进行动画处理的元素设置其CacheMode属性为true 对进行动画处理文本文本元素设置TextRenderingMode属性为RenderForAnimation 对使用不透明度对象和旋转或拉伸对象设置其CacheMode属性为true

3.尽可能使用 Visibility 而不是 Opacity

  如果想设置某个元素不可见,尽量使用Visibility,由于Silverlight的渲染技术Opacity会持续消耗系统资源。通过设置enableRedrawRegions属性你可以更加直观的看出他们的不同,例:

 

<param name=“enableRedrawRegions” value=“true” />

 4.不要对MediaElement与Path元素设置Width与Height

设置这些属性将导致额外的拉伸,这会影响性能。

5.呈现大量图像时使用 Stretch="Fill"

Fill,None 之外的所有其他类型的拉伸都需要计算布局(例如计算居中)。

6.大量数据处理的时候尽量运用BackgroundWorker 在大量数据处理时,会导致插件会停止绘制。 s

相关文章:

  • 2021-07-26
  • 2021-06-01
  • 2021-10-11
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-09
  • 2021-06-20
  • 2021-11-23
  • 2021-12-31
  • 2021-10-27
  • 2021-09-13
  • 2021-09-28
相关资源
相似解决方案