新聞中心
Silverlight插件支持全屏模式,這個沒什么好說的,只需要用設(shè)置IsFullScreen屬性即可,問題在于全屏模式中,盡管屏幕變大了,但是頁面中的控件并未相應(yīng)的變大。

鳳城網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),鳳城網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為鳳城1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的鳳城做網(wǎng)站的公司定做!
推薦專題:走向銀光 一步一步學Silverlight
第1種方式,即應(yīng)用圖片的Stretch屬性:
Click事件代碼:
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
- }
這里主要是將Image的Stretch屬性設(shè)置為UniformToFill,這樣圖片就可以根據(jù)瀏覽器分辨率的變化而變化,這種方式在處理圖片,視頻等資源時比較方便,不過使用這種方式在插入模式下使用圖片時,你需要進行一些處理,因為若你在Image中指定Width或Height,圖片在全屏模式下會保持這個固定的大小。
第2種方式則在后臺進行處理
當處于全屏模式時,該頁面上的控件也進行變化,以Button為例。這種方式或許更貼近我們平常接觸的全屏,我們看看這部分的實現(xiàn):
這里在UI中添加了一個名為RootLayoutScaleTransform的放大轉(zhuǎn)換,后臺代碼主要是根據(jù)插件的Resized,F(xiàn)ullScreenChanged事件進行處理的,所以我們在構(gòu)造函數(shù)中聲明。
- Application.Current.Host.Content.Resized += new EventHandler(Content_Resized);
- Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_Resized);
完整的代碼:
- private double width;
- private double height;
- public double uniformScaleAmount = 1;
- public MainPage()
- {
- InitializeComponent();
- height = this.Height;
- width = this.Width;
- Application.Current.Host.Content.Resized += new EventHandler(Content_Resized);
- Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_Resized);
- }
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
- }
- void Content_Resized(object sender, EventArgs e)
- {
- double currentWidth = Application.Current.Host.Content.ActualWidth;
- double currentHeight = Application.Current.Host.Content.ActualHeight;
- uniformScaleAmount = Math.Min((currentWidth / width), (currentHeight /height));
- RootLayoutScaleTransform.ScaleX = uniformScaleAmount;
- RootLayoutScaleTransform.ScaleY = uniformScaleAmount;
- }
頁面初始化后我們先將當前插件的大小保存了下來,當單擊Button發(fā)生全屏事件時,會進行相關(guān)事件的處理,這種方式我覺得處理的更為妥善一些,程序運行的時候,如果你的界面上什么都沒有,需要設(shè)置UserControl的Width,Height屬性。
原文地址:http://www.cnblogs.com/626498301/archive/2010/08/26/1808883.html
分享名稱:全屏模式下處理Silverlight控件的兩種方式
瀏覽路徑:http://m.5511xx.com/article/dhegeep.html


咨詢
建站咨詢
