温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

全屏模式下如何处理Silverlight控件

发布时间:2021-12-03 11:08:26 来源:亿速云 阅读:116 作者:小新 栏目:编程语言

小编给大家分享一下全屏模式下如何处理Silverlight控件,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

第1种方式,即应用图片的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属性设置为UniformToFill,这样图片就可以根据浏览器分辨率的变化而变化,这种方式在处理图片,视频等资源时比较方便,不过使用这种方式在插入模式下使用图片时,你需要进行一些处理,因为若你在Image中指定Width或Height,图片在全屏模式下会保持这个固定的大小。

第2种方式则在后台进行处理

当处于全屏模式时,该页面上的控件也进行变化,以Button为例。这种方式或许更贴近我们平常接触的全屏,我们看看这部分的实现:

全屏模式下如何处理Silverlight控件

全屏模式下如何处理Silverlight控件

<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中添加了一个名为RootLayoutScaleTransform的放大转换,后台代码主要是根据插件的Resized,FullScreenChanged事件进行处理的,所以我们在构造函数中声明。

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发生全屏事件时,会进行相关事件的处理,这种方式我觉得处理的更为妥善一些,程序运行的时候,如果你的界面上什么都没有,需要设置UserControl的Width,Height属性。

以上是“全屏模式下如何处理Silverlight控件”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI