1. Front-end Code implementation
1.1 Principle See Code injection analysis
<GridMouseDown= "Grid_mousedown"> <Viewport3D> <Viewport3d.camera> <!--The Position property specifies the position of the camera in 3D space, and the Lookdirection property is the camera orientation - <PerspectivecameraPosition= "0 0"lookdirection= "0 0-1" /> </Viewport3d.camera> <Viewport3d.children> <Containeruielement3d> <Viewport2dvisual3d> <Viewport2dvisual3d.geometry> <!--The Positions property represents a collection of points for the drawing object, and the Triangleindices property represents the front and the sides of the object (WPF represents the frontal side by anti-clockwise), and the Texturecoordinates property represents a 2D texture mapping to a 3D object - <!--generally deduced from 3D modeling tools - <MeshGeometry3Dpositions= " -200 0-200-200 0 200-200 0 0"triangleindices= "0 1 2 0 2 3"texturecoordinates= "0 0 0 1 1 1 1 0"/> </Viewport2dvisual3d.geometry> <viewport2dvisual3d.material> <diffusematerialviewport2dvisual3d.isvisualhostmaterial= "True"/> </viewport2dvisual3d.material> <viewport2dvisual3d.visual> <!--placing a front-facing custom user control - <page:win1Width= "The "Height= "The "/> </viewport2dvisual3d.visual> </Viewport2dvisual3d> <Viewport2dvisual3d> <Viewport2dvisual3d.geometry> <MeshGeometry3Dpositions= "0 200-200 0-200-200 0-200 0"triangleindices= "0 1 2 0 2 3"texturecoordinates= "0 0 0 1 1 1 1 0"/> </Viewport2dvisual3d.geometry> <viewport2dvisual3d.material> <diffusematerialviewport2dvisual3d.isvisualhostmaterial= "True"/> </viewport2dvisual3d.material> <viewport2dvisual3d.visual> <!--To place the opposite custom user control - <page:win2Width= "The "Height= "The "/> </viewport2dvisual3d.visual> </Viewport2dvisual3d> <Containeruielement3d.transform> <RotateTransform3D> <rotatetransform3d.rotation> <!--set the axis of rotation to align the y axis of the coordinate system - <axisanglerotation3dx:name= "AAR"Angle= "0"Axis= "0 1 0"/> </rotatetransform3d.rotation> </RotateTransform3D> </Containeruielement3d.transform> </Containeruielement3d> <ModelVisual3D> <modelvisual3d.content> <!--Sets the parallel light fill scene propagating in the specified direction - <DirectionalLightColor= "Transparent"/> </modelvisual3d.content> </ModelVisual3D> </Viewport3d.children> </Viewport3D></Grid>
2, back-end code implementation
2.1 Flip animation with the mouse click the opposite side of the 180-degree display object, the mouse double-click the animation 0 degrees display object front.
Private voidGrid_mousedown (Objectsender, MouseButtonEventArgs e) {DoubleAnimation da=NewDoubleAnimation (); Da. Duration=NewDuration (Timespan.fromseconds (1)); if(E.clickcount = =2) da. to=0d; Elseda. to=180d; Axisanglerotation3d AAR= Application.Current.MainWindow.FindName ("AAR") asaxisanglerotation3d; Aar. BeginAnimation (Axisanglerotation3d.angleproperty, DA); }3. Operation effect
3.1 as follows
Welcome reprint, but please specify the source: http://www.cnblogs.com/julyweb/, thank you!
WPF animations that enable 3D flipping