在网页中浏览视频,使用全屏播放往往能够给用户更好的体验,Silverlight对全屏支持很好,简单几行代码就能搞定全屏的问题。

BrowserHost对象有个属性就是IsFullScreen,设置其为True时就可以实现全屏,设置为False就可以退出全屏,默认情况下按ESC时就可以退出全屏。后来发现,按Alt+Tab也可以,^_*

简单的代码如下:

public void Page_Loaded(object o, EventArgs e)
{
//Required to initialize variables
InitializeComponent();

fullButton.MouseLeftButtonDown += new MouseEventHandler(bgRect_MouseLeftButtonDown);
}

void bgRect_MouseLeftButtonDown(object sender, MouseEventArgs e)
{
if (System.Windows.InteropBrowserHost.IsFullScreen)
{
fullButton.Text = “Click Here to FullScreen”;
System.Windows.InteropBrowserHost.IsFullScreen = false;
}
else
{
fullButton.Text = “Click Here Return to Window”;
System.Windows.InteropBrowserHost.IsFullScreen = true;
}
}

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.