2013-11-28 131 views
0

我有一個分配,我想旋轉一個球存在於橢圓中遞歸應用程序加載並保持旋轉直到它關閉......但我不知道這樣做..任何人請幫助我..在此先感謝。我在XAML代碼是...如何在WPF中旋轉橢圓

<Window Loaded="StartGame" x:Class="PaddingBall.Window1" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      Height="500" Width="700" Background="White" Name="playground" ResizeMode="NoResize"  
      WindowStartupLocation="CenterScreen" SizeToContent="WidthAndHeight"> 
     <Canvas Width="700" Height="500"> 

     <Grid Height="462" Width="700" Canvas.Top="-18"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="700*" /> 
       <ColumnDefinition Width="0*" /> 
       <ColumnDefinition Width="0*" /> 
      </Grid.ColumnDefinitions> 
       <Ellipse Margin="108,88,0,0" Name="ball" Stroke="Black" Height="29"                
        VerticalAlignment="Top" Stretch="UniformToFill" HorizontalAlignment="Left"    
        Width="28" RenderTransformOrigin="0.5,0.5"> 
        <Ellipse.RenderTransform> 
         <TransformGroup> 
          <ScaleTransform/> 
        <SkewTransform/> 
        <RotateTransform Angle="2735.771"/> 
       <TranslateTransform/> 
       </TransformGroup> 
      </Ellipse.RenderTransform> 
       <Ellipse.Fill> 
        <ImageBrush ImageSource="C:\Users\A TECH\Desktop\project\2.jpg"/> 
       </Ellipse.Fill> 
      <Ellipse.BitmapEffect> 
       <BevelBitmapEffect BevelWidth="1" /> 
      </Ellipse.BitmapEffect> 
       <Ellipse.BitmapEffectInput> 
        <BitmapEffectInput /> 
       </Ellipse.BitmapEffectInput> 
     </Ellipse> 
     <Rectangle Height="13" Margin="200,390,0,0" Name="pad" Stroke="Black" 
      VerticalAlignment="Bottom" Fill="Black" HorizontalAlignment="Left" Width="100" /> 
    </Grid> 
</Canvas> 

+0

你應該看看[故事板] (http://msdn.microsoft.com/en-us/libra ry/ms742868(v = vs.110).aspx) – Santux

回答

1

這將肯定把你的橢圓,直到永遠。

<Window x:Class="WpfApplication3.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Window.Resources> 
     <Storyboard x:Key="Storyboard1"> 
      <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="ball"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:1" Value="360"/> 
      </DoubleAnimationUsingKeyFrames> 
     </Storyboard> 
    </Window.Resources> 
    <Window.Triggers> 
     <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
      <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/> 
     </EventTrigger> 
    </Window.Triggers> 
    <Grid> 
     <Canvas Width="700" Height="500"> 

     <Grid Height="462" Width="700" Canvas.Top="-18"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="700*" /> 
       <ColumnDefinition Width="0*" /> 
       <ColumnDefinition Width="0*" /> 
      </Grid.ColumnDefinitions> 
      <Ellipse Margin="108,88,0,0" Name="ball" Stroke="Black" Height="129"                
        VerticalAlignment="Top" Stretch="UniformToFill" HorizontalAlignment="Left"    
        Width="128" RenderTransformOrigin="0.5,0.5"> 
       <Ellipse.RenderTransform> 
        <TransformGroup> 
         <ScaleTransform/> 
         <SkewTransform/> 
         <RotateTransform /> 
         <TranslateTransform/> 
        </TransformGroup> 
       </Ellipse.RenderTransform> 
       <Ellipse.Fill> 
        <ImageBrush ImageSource="C:\Users\A TECH\Desktop\project\2.jpg"/> 
       </Ellipse.Fill> 
       <Ellipse.BitmapEffect> 
        <BevelBitmapEffect BevelWidth="1" /> 
       </Ellipse.BitmapEffect> 
       <Ellipse.BitmapEffectInput> 
        <BitmapEffectInput /> 
       </Ellipse.BitmapEffectInput> 
      </Ellipse> 
      <Rectangle Height="13" Margin="200,390,0,0" Name="pad" Stroke="Black" 
      VerticalAlignment="Bottom" Fill="Black" HorizontalAlignment="Left" Width="100" /> 

     </Grid> 
    </Canvas> 
    </Grid> 
</Window> 
+0

非常感謝你emedo :) – user2996533

+0

@ user2996533隨時接受我的答案,如果它解決了你的問題... –

+0

@emedo Yup它真的幫助我很多..: ) – user2996533