1
我有一個自定義DataGridColumn
,它是爲了促進動畫而創建的。我更新的列的列是可排序(由框架提供)之前,加價低於對WPF中的自定義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
排序?
謝謝你的時間。
人你的好... – MoonKnight
我很困惑,這是如何工作雖然。我的'DataTemplate'是一個'TextBlock',所以我認爲在DataGrid上排序會更加複雜,我們似乎將DataGridColumn的排序與TextBlock中的值混合在一起。在這裏很愚蠢...... – MoonKnight
我不認爲它關心DataTemplate,它會對我的綁定屬性進行排序,如果你想按照文本塊中的實際文本排序,如果它不同於'KeyIndex',你將不得不得到更復雜的,就DataGrid而言,它只會按照它所知道的屬性進行排序(KeyIndex,FileName,ResourceName) –