Silverlight样式(Style)的定义与引用

类似css的方式。

定义:.header{color:red;}
应用:<div class='header'></div>
Silverlight定义样式是这样:在App.xaml中定义如下:
在这里定义了DataGrid的Header样式与Element的样式。
注意添加引用:xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"

大气象
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:sdk
="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
             x:Class
="HCLoad.App"
             
>
    
<Application.Resources>
        
<Style x:Name="DataGridBuildHeader" TargetType="sdk:DataGridColumnHeader">
            
<Setter Property="Width" Value="83"></Setter>
            
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
        
</Style>
        
<Style x:Name="DataGridBuildElement" TargetType="TextBlock">
            
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
        
</Style>
    
</Application.Resources>
</Application>

 

引用样式:

大气象
<sdk:DataGrid x:Name="dgBuilding" Margin="5 55 10 0" Width="500" Height="160" AutoGenerateColumns="False">
    
<sdk:DataGrid.Columns>
        
<sdk:DataGridTextColumn Header="楼层号" Binding="{Binding ID}" HeaderStyle="{StaticResource DataGridBuildHeader}" ElementStyle="{StaticResource DataGridBuildElement}"></sdk:DataGridTextColumn>
    
</sdk:DataGrid.Columns>
</sdk:DataGrid>

 


 

posted @ 2010-07-23 09:56  大气象  阅读(2783)  评论(6编辑  收藏  举报
http://www.tianqiweiqi.com