我有一个自定义DataGridColumn
,它是为了方便动画而创建的。在我更新列之前,该列是可排序的(由框架提供),标记位于
<controls:ResourceDataGrid x:Name="resourceDataGrid"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutoGenerateColumns="false"
GridLinesVisibility="None"
RowHeaderWidth="0"
CanUserAddRows="True"
CanUserDeleteRows="True"
ItemsSource="{Binding Path=Resources,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged,
IsAsync=True}"
dataAccess:DataGridTextSearch.SearchValue="{Binding ElementName=searchBox,
Path=Text,
UpdateSourceTrigger=PropertyChanged}"
dataAccess:DataGridTextSearch.IsAnyTextMatch="False">
<controls:ResourceDataGrid.Columns>
<!--<DataGridTemplateColumn CellTemplate="{StaticResource readOnlyCellUpdatedStyle}" IsReadOnly="True"/>-->
<DataGridTextColumn Header="KeyIndex" Binding="{Binding KeyIndex}" IsReadOnly="True"/>
<DataGridTextColumn Header="FileName" Binding="{Binding FileName}" IsReadOnly="True"/>
<DataGridTextColumn Header="ResourceName" Binding="{Binding ResourceName}" IsReadOnly="False"/>
<controls:CollectionTextColumn Collection="ResourceStringList" Visibility="Collapsed"/>
</controls:ResourceDataGrid.Columns>
新列在上面显示为已注释,这是阻止列可排序的原因。 DataGridTemplateColumn
的代码位于
<DataTemplate x:Key="readOnlyCellUpdatedStyle">
<TextBlock Text="{Binding KeyIndex,
NotifyOnTargetUpdated=True,
Mode=TwoWay}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="0:0:1.5"
From="Transparent" To="Orange" RepeatBehavior="1x"
AutoReverse="True">
<ColorAnimation.EasingFunction>
<ExponentialEase EasingMode="EaseInOut"/>
</ColorAnimation.EasingFunction>
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
如何对此DataGridTemplateColumn
进行排序?
感谢您的时间。
答案 0 :(得分:2)
您需要在SortMemberPath
DataGridTemplateColumn
也许试试:
<DataGridTemplateColumn SortMemberPath="KeyIndex" CellTemplate="{StaticResource readOnlyCellUpdatedStyle}" IsReadOnly="True"/>