2011-01-19 47 views
2

我試圖做一個幻想閃爍的圖標和動畫的GeometryDrawing的畫筆,並不知道如何做到這一點。可能嗎?如何爲GeometryDrawing的屬性設置動畫效果?

下面是一些基本的XAML

<Window.Resources> 
    <GeometryDrawing x:Key="_geometryTest" Brush="#FF6C897B" Geometry="F1 M 66,188L 194,60L 322,188L 250.889,188L 250.889,348L 137.111,348L 137.111,188L 66,188 Z "> 
     <GeometryDrawing.Pen> 
      <Pen LineJoin="Round" Brush="#FF000000"/> 
     </GeometryDrawing.Pen>  
    </GeometryDrawing> 
</Window.Resources> 
<Grid> 
    <Image> 
     <Image.Source> 
      <DrawingImage x:Name="_myImage" Drawing="{StaticResource _geometryTest}"/> 
     </Image.Source> 
    </Image> 
    </Grid> 

回答

2

使用它ColorAnimation。此示例將在加載Window時啓動動畫

<Window.Resources> 
    <GeometryDrawing x:Key="_geometryTest" 
        Brush="#FF6C897B" 
        Geometry="F1 M 66,188L 194,60L 322,188L 250.889,188L 250.889,348L 137.111,348L 137.111,188L 66,188 Z"> 
     <GeometryDrawing.Pen> 
      <Pen LineJoin="Round" Brush="#FF000000"/> 
     </GeometryDrawing.Pen> 
    </GeometryDrawing> 
</Window.Resources> 
<Window.Triggers> 
    <EventTrigger RoutedEvent="Window.Loaded"> 
     <BeginStoryboard> 
      <Storyboard> 
       <ColorAnimation Storyboard.TargetName="myImage" 
           Storyboard.TargetProperty="(Image.Source).(DrawingImage.Drawing).(GeometryDrawing.Brush).(SolidColorBrush.Color)" 
           To="Red" 
           Duration="0:0:0.5" 
           AutoReverse="True" 
           RepeatBehavior="Forever" /> 
      </Storyboard> 
     </BeginStoryboard> 
    </EventTrigger> 
</Window.Triggers> 
<Grid> 
    <Image Name="myImage"> 
     <Image.Source> 
      <DrawingImage x:Name="_myImage" Drawing="{StaticResource _geometryTest}"/> 
     </Image.Source> 
    </Image> 
</Grid> 
+0

嵌套的TargetProperty語法就是我一直在尋找的謝謝! – kbeal2k 2011-01-20 16:50:46

相關問題