Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I would like to know the C# (Code-behind) equivalent of the following XAML code. Please Help.

XML
<Window.Triggers>
     <EventTrigger  SourceName="button1"
     RoutedEvent= "Button.Click">
     <EventTrigger.Actions>

          <BeginStoryboard>
             <Storyboard Name="myStoryBoardX">
                 <DoubleAnimation
         Storyboard.TargetName="rotationX"
         Storyboard.TargetProperty="Angle"
         From="0" To="360" Duration="0:0:15" RepeatBehavior="Forever"/>
             </Storyboard>
         </BeginStoryboard>
         <BeginStoryboard>
             <Storyboard Name="myStoryBoardY">
                 <DoubleAnimation
         Storyboard.TargetName="rotationY"
         Storyboard.TargetProperty="Angle"
         From="0" To="360" Duration="0:0:12" RepeatBehavior="Forever"/>
             </Storyboard>
         </BeginStoryboard>

         <BeginStoryboard>
             <Storyboard TargetName="translate">
                 <DoubleAnimation Storyboard.TargetProperty="OffsetX"
                                    From="0" To="20" Duration="0:0:0.5"
                                    AutoReverse="True" RepeatBehavior="Forever" />

                 <DoubleAnimation Storyboard.TargetProperty="OffsetZ"
                                    From="0" To="-20" Duration="0:0:10"
                                    AutoReverse="True" RepeatBehavior="Forever" />

             </Storyboard>
         </BeginStoryboard>
     </EventTrigger.Actions>
 </EventTrigger>
 </Window.Triggers>





XML
<ModelVisual3D x:Name ="visual">

                              <ModelVisual3D.Transform>
                      <Transform3DGroup>
                              <TranslateTransform3D x:Name="translate">

                              </TranslateTransform3D>


                           <RotateTransform3D>
                              <RotateTransform3D.Rotation>
                                  <AxisAngleRotation3D  x:Name="rotationY"
                                                        Angle="0" Axis="0,1,0" />
                              </RotateTransform3D.Rotation>
                          </RotateTransform3D>
                          <RotateTransform3D>
                              <RotateTransform3D.Rotation>
                                  <AxisAngleRotation3D  x:Name="rotationX"
                                                        Angle="0" Axis="1,0,0" />
                              </RotateTransform3D.Rotation>
                          </RotateTransform3D>
                      </Transform3DGroup>
                  </ModelVisual3D.Transform>

                  </ModelVisual3D>
Posted
Updated 31-Aug-11 0:22am
v2

1 solution

Why can't you work it out yourself? You have everything required to figure it out right in front of you. Intellisense will help you, too.

EDIT ======================

Google helps too:

MSDN - Sample that shows how to create a transform programatically[^]

It should be equally easy to find sample code that builds your triggers the same way.
 
Share this answer
 
v3
Comments
steersteer 31-Aug-11 6:47am    
If I had known how to work it out, I wouldn't have asked your help here. would I ? I did write a piece of equivalent code in C#, but it does not work. I can post that as well if needed. Thanks for your reply anyway. PS: I am very new to programming.
#realJSOP 31-Aug-11 7:29am    
The secret to converting XAML to code behind is to create your objects from the innermost xaml to the outermost. And yes, showing us what you've tried is better than not showing us. My answer also would have been a lot different if you had mentioned that. One last piece of advice - don't cop an attitude. You came here for help - we didn't seek you out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900