Silverlight效能最佳化

來源:互聯網
上載者:User

作者:Nasa 文章出處:我和未來有約會 (http://nasa.cnblogs.com/) 

效能最佳化

監視效能(FPS)【FPS(Frames Per Second):每秒傳輸幀數。】

Silverlight的呈現效能會因指定的宿主參數和內容的複雜程度而異。 為了監視FPS的值我們在開發的過程中將EnableFrameRateCounter屬性設定為 true。這樣瀏覽器的狀態列中顯示所呈現的 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.