You can use the Rotate and RotateTo methods to rotate or smoothly rotate the cube to a specific angle. For more information, see Cube Rotation. In this topic you'll add two buttons to your application, one that rotate the cube instantly using the Rotate method and one that will rotate the cube smoothly using the RotateTo method.
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 "Rotate".
4. Select Button2, navigate to the Properties window and set its Content property to "RotateTo".
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="Button1" VerticalAlignment="Top" Width="75" Click="Button1_Click">Rotate</Button>
<Button Height="23" HorizontalAlignment="Left" Margin="10,95,0,0" Name="Button2" VerticalAlignment="Top" Width="75" Click="Button2_Click">RotateTo</Button>
The page should now look similar to the following:
7. In Code view, add the following import statements to the top of the page:
Imports C1.WPF
Imports C1.WPF.Legacy
•C#
using C1.WPF;
using C1.WPF.Legacy;
8. Add code to the Click event handlers so they look like the following:
Private Sub Button1_Click(ByVal sender as Object, ByVal e as RoutedEventArgs)
C1Cube1.Rotate(50,50,50)
End Sub
Private Sub Button2_Click(ByVal sender as Object, ByVal e as RoutedEventArgs)
C1Cube1.RotateTo(200,200,200, 1)
End Sub
•C#
private void button1_Click(object sender, RoutedEventArgs e)
{
this.c1Cube1.Rotate(50,50,50);
}
private void button2_Click(object sender, RoutedEventArgs e)
{
this.c1Cube1.RotateTo(200,200,200, 1);
}
This code rotates the cube to a set location when the buttons are clicked.
What You've Accomplished
In this topic you used the Rotate and RotateTo methods to rotate or smoothly rotate the cube to a specific angle. Run the application and click the Rotate button. Notice that the cube immediately turns to new location. Click the RotateTo button, notice that the cube turns to the new location smoothly with the delay specified in code.