排序插入符号不显示
Sort Caret Not Displaying
我在使用提供的样式(我可以更改它)时遇到问题,大多数时候我得到排序插入符号,但在一种情况下我没有。
这是风格:
<Style x:Key="StyleDataGridHeader" TargetType="DataGridColumnHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type DataGridColumndHeader}">
<Grid x:Name="gridColumn background="{DynamicResource TableHeaderBackground}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
x:name:"columnText" Grid.Column="0" HorizontalAlignment="Left" Background="{DynamicResource TableHeaderBackground}"
Focusable="False" Foreground="{DynamicResource TableHeaderFontColor}"
Text="{TemplateBinding Content}" />
<Path
x:Name"SortArrow" Grid.Column="0" Width="10" Height="10"
Fill="{DynamicResource TableColumnHeaderCaretColor}"
Focusable="False"
Style="{StaticResource CaretIconLeft}"
Visibility="Collapsed" />
<Thumb
x:Name="PART_LeftHeaderGripper"
Style="StaticResource ColumnHeaderGripStyle" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="SortDirection" Value="Ascending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
<Setter TargetName="columnText" Property="Foreground" Value="{DynamicResource TableColumnHeaderFocusColor}" />
<Setter TargetName="SortArrow" Property="LayoutTransform">
<Setter.value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="SortDirection" Value="Decending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
<Setter TargetName="columnText" Property="Foreground" Value="{DynamicResource TableColumnHeaderFocusColor}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="columnText" Property="Foreground" Value="{DynamicResource TableColumnHeaderFocusColor}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
下面是控件的摘录,其中一列有效,一列无效:
<UserControl
...
<Grid ...
<!-- This one works (sort caret displayed) -->
<DataGridTemplateColumn
Width="50"
SortMemberpath="ColA"
SortDirection="Ascending"
CellStyle="{StaticResource DataGridCellCenter}"
HeaderStyle="{StaticResource DataGridHeaderCenter}"
Header="COL-A">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Path Style="{StaticResource CircleIcon}" Fill="{Binding ColA}" />
</DataTemplate
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn
<!-- This one doesn't work (sort caret not displayed) -->
<DataGridTemplateColumn
Width="300"
SortMemberpath="ColB"
SortDirection="Ascending"
CellStyle="{StaticResource DataGridCellCenter}"
HeaderStyle="{StaticResource DataGridHeaderCenter}"
Header="COL-B">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding IconVals, Mode=OneWay}"/>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:StandardButtonControl
State="{Binding BState}"
Label="{Binding BLabel}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl />
</DataTemplate
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn
</Grid>
</UserControl>
不工作的情况稍微复杂一点,但我想不出缺少什么;任何指导将不胜感激。
您在触发器中签入的 SortDirection 可能以 Null 开始,因此您的路径将保持可见性折叠状态。
我在使用提供的样式(我可以更改它)时遇到问题,大多数时候我得到排序插入符号,但在一种情况下我没有。
这是风格:
<Style x:Key="StyleDataGridHeader" TargetType="DataGridColumnHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type DataGridColumndHeader}">
<Grid x:Name="gridColumn background="{DynamicResource TableHeaderBackground}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
x:name:"columnText" Grid.Column="0" HorizontalAlignment="Left" Background="{DynamicResource TableHeaderBackground}"
Focusable="False" Foreground="{DynamicResource TableHeaderFontColor}"
Text="{TemplateBinding Content}" />
<Path
x:Name"SortArrow" Grid.Column="0" Width="10" Height="10"
Fill="{DynamicResource TableColumnHeaderCaretColor}"
Focusable="False"
Style="{StaticResource CaretIconLeft}"
Visibility="Collapsed" />
<Thumb
x:Name="PART_LeftHeaderGripper"
Style="StaticResource ColumnHeaderGripStyle" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="SortDirection" Value="Ascending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
<Setter TargetName="columnText" Property="Foreground" Value="{DynamicResource TableColumnHeaderFocusColor}" />
<Setter TargetName="SortArrow" Property="LayoutTransform">
<Setter.value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="SortDirection" Value="Decending">
<Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
<Setter TargetName="columnText" Property="Foreground" Value="{DynamicResource TableColumnHeaderFocusColor}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="columnText" Property="Foreground" Value="{DynamicResource TableColumnHeaderFocusColor}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
下面是控件的摘录,其中一列有效,一列无效:
<UserControl
...
<Grid ...
<!-- This one works (sort caret displayed) -->
<DataGridTemplateColumn
Width="50"
SortMemberpath="ColA"
SortDirection="Ascending"
CellStyle="{StaticResource DataGridCellCenter}"
HeaderStyle="{StaticResource DataGridHeaderCenter}"
Header="COL-A">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Path Style="{StaticResource CircleIcon}" Fill="{Binding ColA}" />
</DataTemplate
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn
<!-- This one doesn't work (sort caret not displayed) -->
<DataGridTemplateColumn
Width="300"
SortMemberpath="ColB"
SortDirection="Ascending"
CellStyle="{StaticResource DataGridCellCenter}"
HeaderStyle="{StaticResource DataGridHeaderCenter}"
Header="COL-B">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding IconVals, Mode=OneWay}"/>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:StandardButtonControl
State="{Binding BState}"
Label="{Binding BLabel}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl />
</DataTemplate
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn
</Grid>
</UserControl>
不工作的情况稍微复杂一点,但我想不出缺少什么;任何指导将不胜感激。
您在触发器中签入的 SortDirection 可能以 Null 开始,因此您的路径将保持可见性折叠状态。