Silverlight开发工具在实际使用中,有很多功能和使用技巧值得我们去深入的探讨,总结,以此来方便我们的开发程序效率。在这里就介绍一下有关Silverlight捕获事件的实现方法。#t#
有时候,我们需要在全屏模式和普通模式之间切换时,添加一个其它的代码,这时可以使用事件FullScreenChanged。
- public Page()
- {
- InitializeComponent();
- Application.Current.Host.
Content.FullScreenChanged +=
new EventHandler(Content_
FullScreenChanged); - }
实现Silverlight捕获事件处理
private void Content_FullScreen
Changed(object sender, EventArgs e)
{
Content contentObject = Application.
Current.Host.Content;
if (contentObject.IsFullScreen)
{
toggleButton.Background = new
SolidColorBrush(Colors.Green);
toggleButton.Content = "Full
Screen Mode";
}
else
{
toggleButton.Background = new
SolidColorBrush(Colors.Red);
toggleButton.Content =
"Normal Mode";
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
在普通模式和全屏模式之间切换时,改变按钮的背景色和文字。
完整的Silverlight捕获事件代码如下:
public partial class Page :
UserControl
{
public Page()
{
InitializeComponent();
Application.Current.Host.Content.
FullScreenChanged += new
EventHandler(Content_FullScreenChanged);
}
private void toggleButton_Click
(object sender, RoutedEventArgs e)
{
Content contentObject =
Application.Current.Host.Content;
contentObject.IsFullScreen =
!contentObject.IsFullScreen;
}
private void Content_FullScreen
Changed(object sender, EventArgs e)
{
Content contentObject = Application.
Current.Host.Content;
if (contentObject.IsFullScreen)
{
toggleButton.Background = new
SolidColorBrush(Colors.Green);
toggleButton.Content = "Full
Screen Mode";
}
else
{
toggleButton.Background = new
SolidColorBrush(Colors.Red);
toggleButton.Content =
"Normal Mode";
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
Silverlight捕获事件的相关实现方法就为大家介绍到这里。