第07课 全屏模式支持

news/2024/7/7 15:21:41 标签: silverlight, object, image, button, class
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

本文为系列文章第七篇,介绍如何在Silverlight 2中使用全屏模式。

实现全屏模式

全屏模式有时候是非常有用的,在Silverlight中,提供了很好的支持。实现起来也非常的简单,其实只有一行代码,编写一个简单的XAML。

class="code"><Canvas Background="#46461F">
    <Button x:Name="toggleButton" Background="Red" Width="200" Height="80"
            Canvas.Top="80" Canvas.Left="150" Content="Toggle Full Screen"
            FontSize="20" Click="toggleButton_Click"/>
    <Image x:Name="class="tags" href="/tags/IMAGE.html" title=image>image" Source="smile_6.png" 
           Canvas.Top="100" Canvas.Left="40"></Image>
</Canvas>

引入命名空间

class="code">using System.Windows.Interop;

在按钮单击事件中添加实现代码。

class="code">private void toggleButton_Click(class="tags" href="/tags/OBJECT.html" title=object>object sender, RoutedEventArgs e)
{
    Content contentObject = Application.Current.Host.Content;
    contentObject.IsFullScreen = !contentObject.IsFullScreen;
}

获取当前的Silverlight插件“Content”对象,并设置IsFullScreen属性。运行后单击按钮将会变为全屏模式,再次单击按钮(或者按Esc键)返回普通模式。

class="tags" href="/tags/IMAGE.html" title=image>images.cnblogs.com/cnblogs_com/Terrylee/WindowsLiveWriter/Silverlight27_A002/TerryLee_Silverlight2_0039_thumb.gif" border="0" alt="TerryLee_Silverlight2_0039" width="654" height="326" />

捕获相关事件

有时候,我们需要在全屏模式和普通模式之间切换时,添加一个其它的代码,这时可以使用事件FullScreenChanged。

class="code">public Page()
{
    InitializeComponent();
    Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
}

实现事件处理

class="code">private void Content_FullScreenChanged(class="tags" href="/tags/OBJECT.html" title=object>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";
    }
}

在普通模式和全屏模式之间切换时,改变按钮的背景色和文字。运行后点击按钮:

class="tags" href="/tags/IMAGE.html" title=image>images.cnblogs.com/cnblogs_com/Terrylee/WindowsLiveWriter/Silverlight27_A002/TerryLee_Silverlight2_0040_thumb.gif" border="0" alt="TerryLee_Silverlight2_0040" width="506" height="245" />

切换为普通模式:

class="tags" href="/tags/IMAGE.html" title=image>images.cnblogs.com/cnblogs_com/Terrylee/WindowsLiveWriter/Silverlight27_A002/TerryLee_Silverlight2_0041_thumb.gif" border="0" alt="TerryLee_Silverlight2_0041" width="547" height="397" />

完整的代码如下:

class="code">public partial class Page : UserControl
{
    public Page()
    {
        InitializeComponent();
        Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
    }

    private void toggleButton_Click(class="tags" href="/tags/OBJECT.html" title=object>object sender, RoutedEventArgs e)
    {
        Content contentObject = Application.Current.Host.Content;
        contentObject.IsFullScreen = !contentObject.IsFullScreen;
    }

    private void Content_FullScreenChanged(class="tags" href="/tags/OBJECT.html" title=object>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";
        }
    }
}

结束语

本文简单介绍了Silverlight 2中对于全屏模式的支持,你可以从这里下载本文示例代码。


http://www.niftyadmin.cn/n/1706823.html

相关文章

linux文件系统课设总结,操作系统课程设计报告:Linux二级文件系统设计.doc

操作系统课程设计报告&#xff1a;Linux二级文件系统设计专 业&#xff1a;计算机科学与技术学 号&#xff1a;********姓 名&#xff1a;***提交日期&#xff1a;2013-3-8【设计目的】(1)本实验的目的是通过一个简单多用户文件系统的设计&#xff0c;加深理解文件系统的内部功…

nyist 163 Phone List

Phone List 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB难度&#xff1a;4描述Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Lets say the phone catalogue listed these numbers…

第08课 使用样式封装控件观感

本文为系列文章第八篇&#xff0c;主要介绍在Silverlight中使用Style元素封装控件观感 Silverlight 支持一种 Style 机制&#xff0c;它允许我们把控件的属性值封装成可重用的资源。我们可以把这些样式声明保存在独立于页面的其他文件中&#xff0c;然后就可以在一个应用程序中…

iphone开发笔记目录

自学Iphone有段时间了&#xff0c;现把博客中iphone开发相关整理一下&#xff0c;方便后人查看&#xff1a; 1 hello world 1.1 第一iPhone程序-Hello World 1.2 IOS SDK介绍 1.3 修改iOS工程属性 2 ios UI基础 2.1 增强版Hello World 2.2 MVC设计模式 …

linux 使用ci框架,【原创】Linux PSCI框架

背景Read the fucking source code! --By 鲁迅A picture is worth a thousand words. --By 高尔基说明&#xff1a;Kernel版本&#xff1a;4.14ARM64处理器使用工具&#xff1a;Source Insight 3.5&#xff0c; Visio1. 介绍PSCI, Power State Coordination Interface&#xff…

对信号注册函数signal的理解1

signal函数的原型是&#xff1a; void (*signal(int signum, void (*handler)(int)))(int); 参数说明&#xff1a; signum&#xff1a;指定的信号 其中函数指针handler的取值&#xff1a; SIG_IGN 忽略该信号SIG_DFL 采用系统默认方式处理信号自定义的信号处理函数指针其中的参…

cd linux menu.lst,Windows 7 中使用 grldr + menu.lst 引導 linux系統和win7.

由 kisppuuyy 于 星期五, 02/05/2010 - 22:11 发表由于win7系統啟動的引導方式于xp系統不同, 通過反復試驗于網上搜索的多種方法,總算找到了下述辦法:使用 grldr menu.lst 引導 linux系統和win7.首選備份bcd(為此付出了多次重裝win7的慘痛代價...):/createstore 创建一个新的空…

停车场管理系统c语言程序,C语言停车场管理系统源代码.doc

C语言停车场管理系统源代码#include#include#define stacksize 2 //车站//容量///typedef struct Snode{int number;float int_time[2];float bian_time[2];}record;typedef struct {record *base;record *top;int size;}Stack;/typedef struct Qnode{int number;float int_tim…