2011-11-15 92 views
0

Datagrid具有更好看的列標題(漸變等)。有人有一些XAML模仿Datagrid用於GridView的樣式嗎?GridView列標題樣式

UPDATE

我發現了一些很接近,但仍然不相同:

 <Style x:Key="DataGridColumnHeaderStyle1" TargetType="sdk:DataGridColumnHeader"> 
       <Setter Property="Foreground" Value="#FF000000"/> 
       <Setter Property="HorizontalContentAlignment" Value="Left"/> 
       <Setter Property="VerticalContentAlignment" Value="Center"/> 
       <Setter Property="IsTabStop" Value="False"/> 
       <Setter Property="SeparatorBrush" Value="#FFC9CACA"/> 
       <Setter Property="Padding" Value="4"/> 
       <Setter Property="Template"> 
         <Setter.Value> 
           <ControlTemplate TargetType="sdk:DataGridColumnHeader"> 
             <Grid x:Name="Root"> 
               <Grid.ColumnDefinitions> 
                 <ColumnDefinition/> 
                 <ColumnDefinition Width="Auto"/> 
               </Grid.ColumnDefinitions> 
               <VisualStateManager.VisualStateGroups> 
                 <VisualStateGroup x:Name="CommonStates"> 
                   <VisualState x:Name="Normal"/> 
                   <VisualState x:Name="MouseOver"> 
                     <Storyboard> 
                       <ColorAnimation Duration="0" To="#FF448DCA" Storyboard.TargetProperty="(Fill).Color" Storyboard.TargetName="BackgroundRectangle"/> 
                       <ColorAnimation Duration="0" To="#7FFFFFFF" Storyboard.TargetProperty="(Fill).(GradientStops)[3].Color" Storyboard.TargetName="BackgroundGradient"/> 
                       <ColorAnimation Duration="0" To="#CCFFFFFF" Storyboard.TargetProperty="(Fill).(GradientStops)[2].Color" Storyboard.TargetName="BackgroundGradient"/> 
                       <ColorAnimation Duration="0" To="#F2FFFFFF" Storyboard.TargetProperty="(Fill).(GradientStops)[1].Color" Storyboard.TargetName="BackgroundGradient"/> 
                     </Storyboard> 
                   </VisualState> 
                   <VisualState x:Name="Pressed"> 
                     <Storyboard> 
                       <ColorAnimation Duration="0" To="#FF448DCA" Storyboard.TargetProperty="(Fill).Color" Storyboard.TargetName="BackgroundRectangle"/> 
                       <ColorAnimation Duration="0" To="#D8FFFFFF" Storyboard.TargetProperty="(Fill).(GradientStops)[0].Color" Storyboard.TargetName="BackgroundGradient"/> 
                       <ColorAnimation Duration="0" To="#C6FFFFFF" Storyboard.TargetProperty="(Fill).(GradientStops)[1].Color" Storyboard.TargetName="BackgroundGradient"/> 
                       <ColorAnimation Duration="0" To="#8CFFFFFF" Storyboard.TargetProperty="(Fill).(GradientStops)[2].Color" Storyboard.TargetName="BackgroundGradient"/> 
                       <ColorAnimation Duration="0" To="#3FFFFFFF" Storyboard.TargetProperty="(Fill).(GradientStops)[3].Color" Storyboard.TargetName="BackgroundGradient"/> 
                     </Storyboard> 
                   </VisualState> 
                 </VisualStateGroup> 
                 <VisualStateGroup x:Name="SortStates"> 
                   <VisualState x:Name="Unsorted"/> 
                   <VisualState x:Name="SortAscending"> 
                     <Storyboard> 
                       <DoubleAnimation Duration="0" To="1.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SortIcon"/> 
                     </Storyboard> 
                   </VisualState> 
                   <VisualState x:Name="SortDescending"> 
                     <Storyboard> 
                       <DoubleAnimation Duration="0" To="1.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SortIcon"/> 
                       <DoubleAnimation Duration="0" To="-.9" Storyboard.TargetProperty="(RenderTransform).ScaleY" Storyboard.TargetName="SortIcon"/> 
                     </Storyboard> 
                   </VisualState> 
                 </VisualStateGroup> 
               </VisualStateManager.VisualStateGroups> 
               <Rectangle x:Name="BackgroundRectangle" Grid.ColumnSpan="2" Fill="#FF1F3B53" Stretch="Fill"/> 
               <Rectangle x:Name="BackgroundGradient" Grid.ColumnSpan="2" Stretch="Fill"> 
                 <Rectangle.Fill> 
                   <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0"> 
                     <GradientStop Color="#FCFFFFFF" Offset="0.015"/> 
                     <GradientStop Color="#F7FFFFFF" Offset="0.375"/> 
                     <GradientStop Color="#E5FFFFFF" Offset="0.6"/> 
                     <GradientStop Color="#D1FFFFFF" Offset="1"/> 
                   </LinearGradientBrush> 
                 </Rectangle.Fill> 
               </Rectangle> 
               <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> 
                 <Grid.ColumnDefinitions> 
                   <ColumnDefinition Width="*"/> 
                   <ColumnDefinition Width="Auto"/> 
                   <ColumnDefinition Width="Auto"/> 
                 </Grid.ColumnDefinitions> 
                 <ContentPresenter Content="{TemplateBinding Content}"/> 
                 <TextBlock Text="{Binding Count}" FontWeight="Bold" Width="10" Grid.Column="1" /> 
                 <Path x:Name="SortIcon" Grid.Column="2" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z " Fill="#FF444444" HorizontalAlignment="Left" Margin="4,0,0,0" Opacity="0" RenderTransformOrigin=".5,.5" Stretch="Uniform" VerticalAlignment="Center" Width="8"> 
                   <Path.RenderTransform> 
                     <ScaleTransform ScaleY=".9" ScaleX=".9"/> 
                   </Path.RenderTransform> 
                 </Path> 
               </Grid> 
               <Rectangle x:Name="VerticalSeparator" Grid.Column="1" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" VerticalAlignment="Stretch" Width="1"/> 
             </Grid> 
           </ControlTemplate> 
         </Setter.Value> 
       </Setter> 
     </Style> 
+0

@Dmitry Uhmm ..你確定這個鏈接? :) – Muis

+0

人們只是試圖幫助你在這裏,喬希。 – 2011-11-16 09:29:48

+0

@Dmitry我明白,只是想讓你知道鏈接是不正確的:它指向這篇文章。 – Muis

回答

0

這個主題可能有助於

<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type WpfToolkit:DataGridColumnHeader}"> 
    <Setter Property="VerticalContentAlignment" Value="Center" /> 
    <Setter Property="Background" Value="{StaticResource HeaderBackgroundBrush}"/> 
    <Setter Property="BorderBrush" Value="{StaticResource HeaderBorderBrush}" /> 
    <Setter Property="BorderThickness" Value="1,1,1,1" /> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, 
       Path=Content}"/> 
      <Setter Property="ToolTipService.InitialShowDelay" Value="300" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

<!-- DataGridColumnHeader Right Gripper Style --> 
<Style x:Key="ColumnHeaderRightGripperStyle" TargetType="{x:Type Thumb}"> 
    <Setter Property="Width" Value="8"/> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="Cursor" Value="SizeWE"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Thumb}"> 
       <Border Padding="{TemplateBinding Padding}" 
         Background="{TemplateBinding Background}"> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
<!-- DataGridColumnHeader Left Gripper Style --> 
<Style x:Key="ColumnHeaderLeftGripperStyle" 
     BasedOn="{StaticResource ColumnHeaderRightGripperStyle}" 
     TargetType="{x:Type Thumb}"> 
    <Setter Property="Width" Value="8"/> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="Cursor" Value="SizeWE"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Thumb}"> 
       <Border Name="Border" 
         Padding="{TemplateBinding Padding}" 
         Background="{TemplateBinding Background}"> 
        <Canvas> 
         <Line RenderOptions.EdgeMode="Aliased" Stroke="#88B0E4" 
           X1="7" Y1="{Binding ElementName=Border, Path=ActualHeight}" 
           X2="7" Y2="0"/> 
        </Canvas> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style>