我试图在GroupStyle头中执行DataGrid上的旋转动画,但无法为Storyboard.TargetProperty属性提供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?
发布于 2014-09-02 11:52:01
您的代码几乎可以正常工作。你只需要做一个改变:
Storyboard.TargetProperty="RenderTransform.(RotateTransform.Angle)"我只用TextBlock测试了它,可以看到它在DataGrid中旋转,所以如果您看不到它在您的DataGrid中旋转,那么您的Name属性Binding是不正确的,或者它的值不是预期的"Three"。
<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.(RotateTransform.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>发布于 2014-09-02 11:25:55
对于对象的旋转,这是一个简单且最好的例子。
<Window x:Class="Animation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Animated Rectangle" Height="350" Width="525">
<Grid>
<StackPanel Margin="10">
<Image Name="MyImage" Source="e:\a.jpg" Width="100" Margin="50" ></Image>
<Rectangle
Name="MyRectangle"
Width="100"
Height="100"
Fill="Blue">
<Rectangle.Triggers>
<!-- Animates the rectangle's opacity. -->
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyImage"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:3"
AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
</StackPanel>
</Grid>
https://stackoverflow.com/questions/25622167
复制相似问题