自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Silverlight 2的Style練習(xí)

開發(fā) 后端
本文針對(duì)Silverlight 2的Style進(jìn)行一個(gè)練習(xí)。Style和CSS的作用基本一樣。

本篇的內(nèi)容較為簡單,主要針對(duì)Silverlight 2的Style進(jìn)行一個(gè)練習(xí)。Style簡要的說就是一些屬性值的集合,
作用和CSS比較像。在Silverlight 2中定義Style只能同用于同種類型的Element。如下代碼:

  1. < Style x:Key="ButtonStyleTwo" TargetType="Button"> 
  2.             < Setter Property="FontFamily" Value="Arial" /> 
  3.             < Setter Property="FontSize" Value="40" /> 
  4.             < Setter Property="Foreground" Value="Blue" /> 
  5.             < Setter Property="Background"> 
  6. < /Style> 


這就是一個(gè)定義好的Style,它只能用于Button組件,看看它如何產(chǎn)生作用,將Style直接嵌入Button:

  1. < Button Content="Button"> 
  2.     < Button.Style> 
  3.          < Style TargetType="Button"> 
  4.               < Setter Property="FontFamily" Value="Arial" /> 
  5.               < Setter Property="FontSize" Value="40" /> 
  6.               < Setter Property="Foreground" Value="Blue" /> 
  7.               < Setter Property="Background"> 
  8.                  < Setter.Value> 
  9.                    < LinearGradientBrush> 
  10.                      < GradientStop Color="Green" Offset="0">< /GradientStop> 
  11.                      < GradientStop Color="Red" Offset="1">< /GradientStop> 
  12.                    < /LinearGradientBrush> 
  13.                  < /Setter.Value> 
  14.               < /Setter> 
  15.          < /Style> 
  16.     < /Button.Style> 
  17. < /Button> 
  18.   

當(dāng)然也可以通過Resource的方式來設(shè)置Style,分別設(shè)置了兩個(gè)Style:ButtonStyleOne、ButtonStyleTwo,
ButtonStyleOne設(shè)置為默認(rèn)Style,ButtonStyleTwo用于在點(diǎn)擊Button后切換Style。

Silverlight 2的Style練習(xí):XAML Code:

  1. < UserControl x:Class="SilverlightTest.Page" 
  2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  4.     Width="400"> 
  5.     < UserControl.Resources> 
  6.         < Style x:Key="ButtonStyleOne" TargetType="Button"> 
  7.             < Setter Property="FontFamily" Value="Georgia" /> 
  8.             < Setter Property="FontSize" Value="40" /> 
  9.             < Setter Property="Foreground" Value="SlateGray" /> 
  10.             < Setter Property="Background"> 
  11.                 < Setter.Value> 
  12.                     < LinearGradientBrush> 
  13.                         < GradientStop Color="Blue" Offset="0">< /GradientStop> 
  14.                         < GradientStop Color="Yellow" Offset="1">< /GradientStop> 
  15.                     < /LinearGradientBrush> 
  16.                 < /Setter.Value> 
  17.             < /Setter> 
  18.         < /Style> 
  19.         < Style x:Key="ButtonStyleTwo" TargetType="Button"> 
  20.             < Setter Property="FontFamily" Value="Arial" /> 
  21.             < Setter Property="FontSize" Value="40" /> 
  22.             < Setter Property="Foreground" Value="Pink" /> 
  23.             < Setter Property="Background"> 
  24.                 < Setter.Value> 
  25.                     < LinearGradientBrush> 
  26.                         < GradientStop Color="Green" Offset="0">< /GradientStop> 
  27.                         < GradientStop Color="Red" Offset="1">< /GradientStop> 
  28.                     < /LinearGradientBrush> 
  29.                 < /Setter.Value> 
  30.             < /Setter> 
  31.         < /Style> 
  32.     < /UserControl.Resources> 
  33.     < StackPanel x:Name="LayoutRoot" Background="White"> 
  34.         < Button x:Name="TestButton" Content="A Customized Button"   
  35.                 Style="{StaticResource ButtonStyleOne}" Click="Button_Click">< /Button> 
  36.     < /StackPanel> 
  37. < /UserControl> 
  38.   

用C#來切換Sytle,如下代碼:

  1. private void Button_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    //切換Style:ButtonStyleTwo  
  4.    TestButton.Style = this.Resources["ButtonStyleTwo"as Style;  
  5.    //修改Button文字  
  6.    TestButton.Content = "Style Changed";  
  7. }  

以上就是Silverlight 2的Style練習(xí)。

【編輯推薦】

  1. 微軟Silverlight 3挑戰(zhàn)Adobe AIR
  2. RIA大戰(zhàn)在即 微軟Silverlight勝算幾何
  3. 圖解Silverlight 3的7個(gè)新功能
  4. Flash與Silverlight多領(lǐng)域?qū)崪y對(duì)比
  5. 微軟宣稱Silverlight裝機(jī)量超過三億
責(zé)任編輯:yangsai 來源: 博客園
相關(guān)推薦

2012-07-05 15:22:18

Silverlight

2009-12-31 17:00:40

Silverlight

2009-02-02 10:53:34

SilverlightSilverlightRIA

2009-02-02 10:08:25

SilverlightTwitterASP.NET

2010-01-04 16:30:06

Silverlight

2011-07-15 14:12:30

Silverlight

2009-05-26 11:33:15

SilverlightIE2微軟

2010-08-09 13:25:02

FlexSilverlight

2009-03-05 11:40:31

ListBox開發(fā)Silverlight

2011-01-26 09:50:18

Silverlight.NetJavaScript

2009-07-16 14:58:16

Windows Emb

2009-06-25 09:00:43

Silverlight

2011-09-30 08:55:12

Silverlight

2009-02-20 08:54:20

DownloaderSilverlight對(duì)象

2009-06-03 10:24:11

LoadMaskSilverlight

2011-01-27 08:49:47

SilverlightWeb.NET

2017-02-06 13:31:19

Android樣式繼承關(guān)系

2010-08-24 13:55:38

DIVstyle

2011-04-18 13:52:31

Ubuntu MAC

2009-07-24 13:40:16

使用SilverLig
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)