Showing a Cube Face

In this topic you'll set the ShowFace method to smoothly rotate the cube so a particular face is facing forward. For more information, see Cube Face. In this topic you'll add two buttons to your application to show particular faces. Note that you can also use the ShowItem method to similarly show a particular item on a cube face.

Complete the following steps:

1.   Navigate to the Toolbox and double-click the Button item twice to add two Button controls to your application.

2.   Move and resize the buttons so that they appear next to the cube.

3.   Select Button1, navigate to the Properties window, and set its Content property to "Show Left".

4.   Select Button2, navigate to the Properties window, and set its Content property to "Show Top".

5.   Double-click Button1 to create the Button_Click event handler and switch to Code view.

6.   Return to Design view and repeat the previous step with the Button2 so each button has a Click event handler specified.

The XAML markup will appear similar to the following:

 

<Button Height="23" HorizontalAlignment="Left" Margin="10,62,0,0" Name="Show Left" VerticalAlignment="Top" Width="75" Click="Button1_Click">Rotate</Button>

<Button Height="23" HorizontalAlignment="Left" Margin="10,95,0,0" Name="Show Top" VerticalAlignment="Top" Width="75" Click="Button2_Click">RotateTo</Button>

 

7.   Switch to Code view and add the following import statements to the top of the page:

      Visual Basic

      C#

8.   Add code to the Click event handlers so they look like the following:

      Visual Basic

      C#

This code rotates the cube to a specific face when each button is clicked.

What You've Accomplished

In this topic you used the ShowFace method to smoothly rotate the cube so a particular face is facing forward. You also set the ShowFaceDelay property to control how quickly the cube moved to the face. Run the application and click the Show Left button. Notice that the cube turns to the Left face smoothly. Click the Show Top button, notice that the cube turns to the new location smoothly with a longer delay as specified in the code.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.