Full Screen In Silverlight

Tính Năng Full Screen trong Silverlight

I.Introduction:

-  Full Screen là một tính năng quen thuộc trong Silverlight, được áp dụng nhiều vào các ứng dụng xem Video …..

– Trong bài này mình xin chia sẻ cách sử dụng Full Screen trong Silverlight.

II.Creating Project And Coding

-Mở Visual Studio lên vào tạo Silverlight Aplication Project:

image

Tiếp theo chúng ta tạo một giao diện đơn giản gồm 1 Buttun để khi click vào thì Ứng dụng sẽ FullScreen, như đoạn code XAML sau:

   1: <UserControl x:Class="FullScreen.MainPage"

   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   4:     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

   5:     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

   6:     mc:Ignorable="d"

   7:     d:DesignHeight="300" d:DesignWidth="400">

   8:  

   9:     <Grid x:Name="LayoutRoot" Background="White">

  10:         <Grid.RowDefinitions >

  11:             <RowDefinition Height="100"/>

  12:             <RowDefinition Height="50"/>

  13:             <RowDefinition Height="*"/>

  14:         </Grid.RowDefinitions>

  15:         <Rectangle Grid.Row="1">

  16:             <Rectangle.Fill>

  17:                 <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">

  18:                     <GradientStop Color="Black" Offset="0" />

  19:                     <GradientStop Color="White" Offset="1" />

  20:                 </LinearGradientBrush>

  21:             </Rectangle.Fill>

  22:         </Rectangle>

  23:         <TextBlock Text="Full Screen Feature" Grid.Row="0" FontSize="28"/>

  24:         <Button Content="Click Me To Full Screen" Grid.Row="2" Click="button1_Click" Margin="1" Name="button1" FontSize="20"/>

  25:     </Grid>

  26: </UserControl>

Bây giờ chúng ta xử lý sự kiện Click cho ứng dụng:

   1: using System;

   2: using System.Collections.Generic;

   3: using System.Linq;

   4: using System.Net;

   5: using System.Windows;

   6: using System.Windows.Controls;

   7: using System.Windows.Documents;

   8: using System.Windows.Input;

   9: using System.Windows.Media;

  10: using System.Windows.Media.Animation;

  11: using System.Windows.Shapes;

  12:  

  13: namespace FullScreen

  14: {

  15:     public partial class MainPage : UserControl

  16:     {

  17:         bool flag = false;

  18:         public MainPage()

  19:         {

  20:             InitializeComponent();

  21:         }

  22:  

  23:         private void button1_Click(object sender, RoutedEventArgs e)

  24:         {

  25:             if (!flag)

  26:             {

  27:                 flag = true;

  28:                 button1.Content = "Click Me To Exit Full Screen !";

  29:             }

  30:             else

  31:             {

  32:                 flag = false;

  33:                 button1.Content = "Click Me To Full Screen !";

  34:             }

  35:             fullScreen();       

  36:         }

  37:         private void fullScreen()

  38:         {

  39:             Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;

  40:         }

  41:     }

  42: }

Chạy ứng dụng và xem kết quả:

image

Sau khi click vào Button:

image

Với một vài dòng Code chúng ta đã có thể tùy chỉnh Full Screen cho ứng dụng Silverlight!

/*Web is beautiful*/

One thought on “Full Screen In Silverlight

Leave a comment