(一)文字居中:
样式文件:<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Primitives="clr-namespace:System.windows.Controls.Primitives;assembly=System.windows.Controls.Data"
xmlns:data="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Data"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<SolIDcolorBrush x:Key="linecolor" color="#FFFF6500"/>
<!-- Resource dictionary entrIEs should be defined here. -->
<Style x:Key="DataGrIDheaderStyle" targettype="Primitives:DataGrIDColumnheader">
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
<Setter Property="FontSize" Value="14.667"/>
<Setter Property="SeparatorBrush" Value="{StaticResource linecolor}"/>
<Setter Property="Background" Value="{StaticResource linecolor}"/>
<Setter Property="borderBrush" Value="{StaticResource linecolor}"/>
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style x:Key="DataGrIDCellStyle" targettype="data:DataGrIDCell">
<Setter Property="HorizontalContentAlignment" Value="Center" ></Setter>
<Setter Property="FontSize" Value="14.667"/>
</Style>
引用样式:
<local:autoFillDataGrID autoGenerateColumns="False" x:name="DataGrID1" GrIDlinesVisibility="All" CellStyle="{StaticResource DataGrIDCellStyle}" RowDetailsVisibilityMode="VisibleWhenSelected" Height="336" ColumnheaderStyle="{StaticResource DataGrIDheaderStyle}" HorizontalGrIDlinesBrush="{StaticResource linecolor}" VerticalGrIDlinesBrush="{StaticResource linecolor}" borderBrush="{StaticResource linecolor}" RowBackground="#33C3FF00">
(二)列头样式
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Data"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vsm="clr-namespace:System.windows;assembly=System.windows"
mc:Ignorable="d">
<SolIDcolorBrush x:Key="linecolor" color="#FFFF6500"/>
<!-- Resource dictionary entrIEs should be defined here. -->
<Style x:Key="DataGrIDCellStyle" targettype="data:DataGrIDCell">
<Setter Property="HorizontalContentAlignment" Value="Center" ></Setter>
<Setter Property="FontSize" Value="14.667"/>
</Style>
<Style x:Key="DataGrIDColumnheaderStyle1" targettype="sdk:DataGrIDColumnheader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="FontSize" Value="14.667"/>
<Setter Property="SeparatorBrush" Value="{StaticResource linecolor}"/>
<Setter Property="Background" Value="{StaticResource linecolor}"/>
<Setter Property="borderBrush" Value="{StaticResource linecolor}"/>
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate targettype="sdk:DataGrIDColumnheader">
<GrID x:name="Root">
<GrID.ColumnDeFinitions>
<ColumnDeFinition/>
<ColumnDeFinition WIDth="auto"/>
</GrID.ColumnDeFinitions>
<vsm:visualstatemanager.VisualStateGroups>
<vsm:VisualStateGroup x:name="CommonStates">
<vsm:VisualStateGroup.Transitions>
<vsm:VisualTransition GeneratedDuration="00:00:0.1"/>
</vsm:VisualStateGroup.Transitions>
<vsm:VisualState x:name="normal"/>
<vsm:VisualState x:name="MouSEOver">
<Storyboard>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundRectangle" Storyboard.TargetProperty="(Fill).color" To="#FF448DCA"/>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundGradIEnt" Storyboard.TargetProperty="(Fill).(GradIEntStops)[3].color" To="#7FFFFFFF"/>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundGradIEnt" Storyboard.TargetProperty="(Fill).(GradIEntStops)[2].color" To="#CCFFFFFF"/>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundGradIEnt" Storyboard.TargetProperty="(Fill).(GradIEntStops)[1].color" To="#F2FFFFFF"/>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:name="pressed">
<Storyboard>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundRectangle" Storyboard.TargetProperty="(Fill).color" To="#FF448DCA"/>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundGradIEnt" Storyboard.TargetProperty="(Fill).(GradIEntStops)[0].color" To="#D8FFFFFF"/>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundGradIEnt" Storyboard.TargetProperty="(Fill).(GradIEntStops)[1].color" To="#C6FFFFFF"/>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundGradIEnt" Storyboard.TargetProperty="(Fill).(GradIEntStops)[2].color" To="#8CFFFFFF"/>
<colorAnimation Duration="0" Storyboard.Targetname="BackgroundGradIEnt" Storyboard.TargetProperty="(Fill).(GradIEntStops)[3].color" To="#3FFFFFFF"/>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
<vsm:VisualStateGroup x:name="SortStates">
<vsm:VisualStateGroup.Transitions>
<vsm:VisualTransition GeneratedDuration="00:00:0.1"/>
</vsm:VisualStateGroup.Transitions>
<vsm:VisualState x:name="Unsorted"/>
<vsm:VisualState x:name="SortAscending">
<Storyboard>
<DoubleAnimation Duration="0" Storyboard.Targetname="SortIcon" Storyboard.TargetProperty="Opacity" To="1.0"/>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:name="SortDescending">
<Storyboard>
<DoubleAnimation Duration="0" Storyboard.Targetname="SortIcon" Storyboard.TargetProperty="Opacity" To="1.0"/>
<DoubleAnimation Duration="0" Storyboard.Targetname="SortIcon" Storyboard.TargetProperty="(Rendertransform).ScaleY" To="-.9"/>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:visualstatemanager.VisualStateGroups>
<Rectangle x:name="BackgroundRectangle" Fill="#FF1F3B53" Stretch="Fill" GrID.ColumnSpan="2" d:IsHIDden="True"/>
<Rectangle x:name="BackgroundGradIEnt" Stretch="Fill" GrID.ColumnSpan="2">
<Rectangle.Fill>
<linearGradIEntBrush EndPoint=".7,1" StartPoint=".7,0">
<GradIEntStop color="#FFE4F37C" Offset="0.015"/>
<GradIEntStop color="#FFE4F37C" Offset="0.894"/>
<GradIEntStop color="#FFFF2601" Offset="0.919"/>
<GradIEntStop color="#FFFF2500" Offset="1"/>
</linearGradIEntBrush>
</Rectangle.Fill>
</Rectangle>
<GrID HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" margin="{TemplateBinding padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<GrID.ColumnDeFinitions>
<ColumnDeFinition/>
<ColumnDeFinition WIDth="auto"/>
</GrID.ColumnDeFinitions>
<ContentPresenter Cursor="{TemplateBinding Cursor}" Content="{TemplateBinding Content}"/>
<Path x:name="SortIcon" Fill="#FF444444" Stretch="Uniform" HorizontalAlignment="left" margin="4,0" VerticalAlignment="Center" WIDth="8" Opacity="0" RendertransformOrigin=".5,.5" GrID.Column="1" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z ">
<Path.Rendertransform>
<Scaletransform ScaleX=".9" ScaleY=".9"/>
</Path.Rendertransform>
</Path>
</GrID>
<Rectangle x:name="VerticalSeparator" Fill="{TemplateBinding SeparatorBrush}" VerticalAlignment="Stretch" WIDth="1" Visibility="{TemplateBinding SeparatorVisibility}" GrID.Column="1"/>
</GrID>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
总结
以上是内存溢出为你收集整理的SILVERLIGHT datagrid 技巧全部内容,希望文章能够帮你解决SILVERLIGHT datagrid 技巧所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)