2012-05-23 50 views
1

我正在尋找合併對象中的多種變換,我發現如何,但問題是,當我試圖把的TransformGroup,它給出了一個錯誤「無法解析的所有屬性引用屬性路徑'RenderTransform.ScaleX'。驗證適用的對象是否支持這些屬性。「WPF中使用的TransformGroup給出了一個錯誤

這裏是我的轉換代碼,我從網上(「感謝那些誰提出這個代碼」)

<Window.Resources> 
    <Storyboard x:Key="expandStoryboard"> 
     <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" 
    To="1.3" Duration="0:0:0.2" /> 
     <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" 
    To="1.3" Duration="0:0:0.2" /> 
    </Storyboard> 
    <Storyboard x:Key="shrinkStoryboard"> 
     <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" 
    To="1" Duration="0:0:0.2" /> 
     <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" 
    To="1" Duration="0:0:0.2" /> 
    </Storyboard> 
    <Storyboard x:Key="shakeStoryBoard"> 
     <DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle" 
          From="-5" To="5" Duration="0:0:0.05" 
          AutoReverse="True" 
          RepeatBehavior="3x" 
          FillBehavior="Stop" /> 
    </Storyboard> 

,這是我對象(按鈕)

 <Button RenderTransformOrigin="0.5,0.5" Background="Transparent" Focusable="False" BorderBrush="Transparent" Height="220" HorizontalAlignment="Left" Margin="591,213,0,0" Name="cmdsettings" VerticalAlignment="Top" Width="189"> 
     <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" Width="217" Height="220"> 
      <Image HorizontalAlignment="Center" VerticalAlignment="Center" Source="Images/settings.png" Height="192" Width="204" /> 
      <TextBlock VerticalAlignment="center" TextAlignment="center" FontSize="16" Width="123" Foreground="white" FontWeight="Bold" Height="20">Settings</TextBlock> 
     </StackPanel> 
     <Button.Triggers> 
      <EventTrigger RoutedEvent="Button.MouseEnter"> 
       <BeginStoryboard Storyboard="{StaticResource expandStoryboard}" /> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="Button.MouseLeave"> 
       <BeginStoryboard Storyboard="{StaticResource shrinkStoryboard}" /> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="Button.Click"> 
       <BeginStoryboard Storyboard="{StaticResource shakeStoryBoard}" /> 
      </EventTrigger> 
     </Button.Triggers> 
     <Button.RenderTransform > 
      <TransformGroup> 
       <ScaleTransform ScaleX="1" ScaleY="1"/> 
       <RotateTransform /> 
      </TransformGroup>      
     </Button.RenderTransform> 
    </Button> 

回答

2

由於Button.RenderTransform複製包含TransformGroup,則必須通過其Children屬性訪問包含的變換:

<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[0].ScaleX" ... /> 
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[0].ScaleY" ... /> 
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[1].Angle" ... /> 
+0

非常感謝你的答覆。是的,它的作品!現在我的下一個計劃是當我點擊時做分散按鈕..感謝您的回答..上帝保佑:) – user1405327