Wiki


Wiki Table of Contents

Page Details

Published by:
This page has not yet been rated

Silverlight Tip of the Day #35 – Full Screen Mode Implementation

Filed under: [Edit Tags]

Để ứng dụng của bạn có thể enter để có chế độ toàn màn hình (full sreen) thì tất cả những điều bạn phải làm là thực thi dòng code sau đây:

Application.Current.Host.Content.IsFullScreen = true;

Mối lần chọn chế độ full screen (toàn màn hình) thì ứng dụng Silverlight của bạn sẽ hiện lên dòng sau trên ứng dụng một vài giây:

image

Điều này có nghĩa là để thoát khỏi chế độ full screen thì bạn chỉ cần nhấn nút <ESC> trên bàn phím. Dĩ nhiên là bạn cũng có thể không cho chế độ này có trong ứng dụng của bạn bằng cách gán  IsFullScreen = false.

Giới hạn/ Hạn chế được biết:

  • Vì lí do bảo mật, bạn không thể gán thuộc tính IsFullScreen một cách trực tiếp nhưng chỉ có thể thể đáp ứng cho một người dùng chọn sự kiện như là một button click.
  • Để ngăn chặn việc đánh cắp mật mã, chỉ những phím sau được cho phép nhập dữ liệu vào khi ở chế độ full screen :
    • space: phím tạo khoảng trắng
    • arrow keys: các phím mũi tên
    • tab: phím tab
    • home: phím home
    • enter: phím enter
    • end: phím end
    • pageup/pagedown: phím pageup/pagedown

Chạy bản demo hoàn thiện ở đây: http://silverlight.services.live.com/invoke/66033/Full%20Screen/iframe.html

Mã code đơn giản của trang  Page.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
 
namespace FullScreen
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ToggleFullScreen();
        }
 
        private void ToggleFullScreen()
        {
            Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
        }
    }
}

Page.xaml:

<UserControl x:Class="FullScreen.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Canvas>
        <Button Click="Button_Click" Content="Toggle Full Screen"></Button>
    </Canvas>
</UserControl>

Thank you,
--Mike Snow

Recent Comments

Leave the first comment for this page.