DataGrid标题排序方向图标

时间:2011-08-30 07:57:40

标签: wpf silverlight xaml datagrid sortdirection

如何在wpf datagrid标题中显示自定义排序方向图像?

我在数据网格中使用这种风格。如何为升序和降序排序方向添加图像?

<Style x:Key="DataGridColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}"  >
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="#fbfdfc" Offset="0.1" />
                    <GradientStop Color="#d4d5d9" Offset="0.9" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="Padding" Value="3"/>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True" />
                    <Condition Property="SortDirection" Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                            <GradientStop Color="#ffd8a8" Offset="0.0" />
                            <GradientStop Color="#ffad41" Offset="0.5" />
                            <GradientStop Color="#fedf78" Offset="0.9" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderBrush" Value="Black" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>

1 个答案:

答案 0 :(得分:2)

如果您想更改需要覆盖Template的三角形,可以在SortDirection上触发并相应地显示不同的图像。 (获取默认模板from MSDNDefault WPF Themes链接))