我定义了一个简单的控件,只是一个红色的正方形,里面有一个黑色的三角形。当用户单击控件时,我想将黑色三角形旋转180度。我需要动画旋转。下面是控件的XAML(和主窗口) -动画控制旋转
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<ControlTemplate x:Key="ControlControlTemplate1" TargetType="{x:Type Control}">
<Grid>
<Border Background="Red"/>
<Path Grid.Row="1" x:Name="myPath" Visibility="Visible" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill"
Width="80" Height="60" Fill="Black" Opacity="1"
VerticalAlignment="Center" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.4">
</Path>
</Grid>
</ControlTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Control HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Template="{DynamicResource ControlControlTemplate1}">
</Control>
</Grid>
- 我尝试设置在控制触发器时按下控制做旋转,但似乎没有IsPressed属性(由于某种原因,还有一个IsMouseOver属性)。所以当IsPressed属性不可用时,我如何触发旋转?
- 我怎样才能使这个动画旋转?
IsPressed属性适用于需要使用OnMouseLeftDown /弥补电网或边境更高控件(按钮)。你可以在Expression Blend中做的动画,我会说试图找到一本关于WPF和动画的书,然后你会很快学会它。 – BigL 2012-01-07 17:09:31