我想在DataGrid的GroupStyle頭部內執行旋轉動畫,並且我無法獲取Storyboard.TargetProperty屬性的PropertyPath語法。下面是一個包含例子來突出我的問題在GroupStyle.HeaderTemplate中指定動畫的PropertyPath語法
<Window x:Class="ImageRotateTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<x:Array Type="sys:String">
<sys:String>One</sys:String>
<sys:String>One</sys:String>
<sys:String>Three</sys:String>
<sys:String>Four</sys:String>
<sys:String>Four</sys:String>
</x:Array>
</Window.DataContext>
<Window.Resources>
<CollectionViewSource Source="{Binding}" x:Key="ViewSource">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription></PropertyGroupDescription>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Window.Resources>
<DataGrid ItemsSource="{Binding Source={StaticResource ViewSource}}" AutoGenerateColumns="False">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}">
<TextBlock.RenderTransform>
<RotateTransform/>
</TextBlock.RenderTransform>
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Name}" Value="Three">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="Test">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle" To="360" Duration="0:0:0.800" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="Test" />
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding}" Header="Item" />
</DataGrid.Columns>
</DataGrid>
這裏的結果應該是組頭應旋轉只爲「三」組,而不是任何其他人。但是,在運行這導致以下異常
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: Cannot resolve all property references in the property path 'RenderTransform.Angle'. Verify that applicable objects support the properties.
我已經試過了Storyboard.TargetProperty以下沒有成功
(TextBlock.RenderTransform).(RotateTransform.Angle)
(RenderTransform).(Angle)
RenderTransform.Angle
我的問題是;如何使用屬性路徑語法來引用TextBlock.RenderTransform?
嘿,你的例子工作正常,但問題是由於它是在datagrid組頭。 Name綁定來自CollectionViewGroupInternal對象,它是GroupItem的datacontext,並且該綁定能正常工作。 – ChrisO 2014-09-02 12:01:05
你是說在DataGrid裏面它*不工作嗎? – Sheridan 2014-09-02 12:19:49
特別是在datagrid頭部內時,是的。 – ChrisO 2014-09-02 12:48:52