您好,登錄后才能下訂單哦!
小編給大家分享一下全屏模式下如何處理Silverlight控件,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
第1種方式,即應(yīng)用圖片的Stretch屬性:
<Grid x:Name="LayoutRoot" Background="White"> <Image Stretch="UniformToFill" Source="/FullScreenModel;component/Koala.jpg" /> <Button Content="全屏" Name="button1" Click="button1_Click" /> </Grid>
Click事件代碼:
private void button1_Click(object sender, RoutedEventArgs e) { Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen; }
這里主要是將Image的Stretch屬性設(shè)置為UniformToFill,這樣圖片就可以根據(jù)瀏覽器分辨率的變化而變化,這種方式在處理圖片,視頻等資源時(shí)比較方便,不過(guò)使用這種方式在插入模式下使用圖片時(shí),你需要進(jìn)行一些處理,因?yàn)槿裟阍贗mage中指定Width或Height,圖片在全屏模式下會(huì)保持這個(gè)固定的大小。
第2種方式則在后臺(tái)進(jìn)行處理
當(dāng)處于全屏模式時(shí),該頁(yè)面上的控件也進(jìn)行變化,以Button為例。這種方式或許更貼近我們平常接觸的全屏,我們看看這部分的實(shí)現(xiàn):
<Grid.RenderTransform> <ScaleTransform ScaleX="1" ScaleY="1" x:Name="RootLayoutScaleTransform"> </ScaleTransform> </Grid.RenderTransform> <Button Name="button1" Content="全屏" Height="30" Width="50" Click="button1_Click" Margin="70,170,72,100"> </Button>
這里在UI中添加了一個(gè)名為RootLayoutScaleTransform的放大轉(zhuǎn)換,后臺(tái)代碼主要是根據(jù)插件的Resized,F(xiàn)ullScreenChanged事件進(jìn)行處理的,所以我們?cè)跇?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; }
頁(yè)面初始化后我們先將當(dāng)前插件的大小保存了下來(lái),當(dāng)單擊Button發(fā)生全屏事件時(shí),會(huì)進(jìn)行相關(guān)事件的處理,這種方式我覺(jué)得處理的更為妥善一些,程序運(yùn)行的時(shí)候,如果你的界面上什么都沒(méi)有,需要設(shè)置UserControl的Width,Height屬性。
以上是“全屏模式下如何處理Silverlight控件”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。