[转]silverlight中定义样式

作用域:定义所有的样式

  1. <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  2.              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  3.              x:Class="SilverlightApplication1.App"  
  4.              >  
  5.     <Application.Resources>  
  6.         <Style TargetType="Button">  
  7.             <Setter Property="Background" Value="Beige"></Setter>  
  8.             <Setter Property="FontSize" Value="25"></Setter>  
  9.             <Setter Property="Foreground" Value="Blue"></Setter>  
  10.             <Setter Property="Margin" Value="20"></Setter>            
  11.         </Style>  
  12.     </Application.Resources>  
  13. </Application>  


一般的样式引用

 

    1. <UserControl x:Class="SilverlightApplication1.SilverlightControl1"  
    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.     <UserControl.Resources>  
    9.         <Style x:Key="button1" TargetType="Button">  
    10.             <Setter Property="Background" Value="Beige"></Setter>  
    11.             <Setter Property="FontSize" Value="25"></Setter>  
    12.             <Setter Property="Foreground" Value="Blue"></Setter>  
    13.             <Setter Property="Margin" Value="20"></Setter>  
    14.         </Style>  
    15.         <Style x:Key="button2" TargetType="Button">  
    16.             <Setter Property="Background" Value="Wheat"></Setter>  
    17.             <Setter Property="FontSize" Value="24"></Setter>  
    18.             <Setter Property="Foreground" Value="Red"></Setter>  
    19.             <Setter Property="Margin" Value="20"></Setter>  
    20.         </Style>  
    21.     </UserControl.Resources>  
    22.   
    23.     <StackPanel x:Name="LayoutRoot1" Width="800" Height="180"   
    24.                     Orientation="Horizontal"  
    25.                     Background="White"  
    26.                     HorizontalAlignment="Center">  
    27.         <Button Content="样式1" Width="200" Height="70" Style="{StaticResource button1}"/>  
    28.         <Button Content="样式1" Width="200" Height="70" Style="{StaticResource button2}"/>  
    29.         <Button Content="样式3"   Width="200" Height="80" >  
    30.             <Button.Style>  
    31.                 <Style TargetType="Button">  
    32.                     <Setter Property="Background" Value="Red"></Setter>  
    33.                     <Setter Property="FontSize" Value="20"></Setter>  
    34.                     <Setter Property="Foreground" Value="Beige"></Setter>  
    35.                     <Setter Property="Margin" Value="20"></Setter>  
    36.                 </Style>  
    37.             </Button.Style>  
    38.         </Button>  
    39.         <Button  Content="App"></Button>  
    40.   
    41.     </StackPanel>  
    42.   
    43. </UserControl>  
posted on 2013-03-22 11:21  SamWang  阅读(521)  评论(0编辑  收藏  举报