av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Silverlight2的Style練習(xí)

本篇的內(nèi)容較為簡單,主要針對Silverlight 2的Style進(jìn)行一個練習(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>

這就是一個定義好的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è)置了兩個Style:ButtonStyleOne、ButtonStyleTwo,
ButtonStyleOne設(shè)置為默認(rèn)Style,ButtonStyleTwo用于在點擊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í)。


網(wǎng)站欄目:Silverlight2的Style練習(xí)
瀏覽路徑:http://uogjgqi.cn/article/dhjsgsi.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流