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>
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>
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="楼层号" Binding="{Binding ID}" HeaderStyle="{StaticResource DataGridBuildHeader}" ElementStyle="{StaticResource DataGridBuildElement}"></sdk:DataGridTextColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。