0
                <RotateTransform3D CenterX="0" CenterY="0" CenterZ="0">
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Axis="0,1,0" Angle="35"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>

For above C# code, I want to set the value of Angle by my c# code (.cs) instead of xaml. So I change it like below:

<AxisAngleRotation3D Axis="0,1,0" Angle="AngleValue"/>

And in my cs code:

public partial class Window1 : Window
{
    int AngleValue;

    public Window1()
    {
        InitializeComponent();

        var t = new DispatcherTimer();
        // 1 second
        t.Interval = new TimeSpan(0, 0, 1);
        t.Tick += RotatePhoto;
        t.IsEnabled = true;
        t.Start();
    }

    private void RotatePhoto(object sender, EventArgs e)
    {
        //var current = this.myViewport3D.Children[0];
        //var translate = (current.Transform as Transform3DGroup).Children[0] as TranslateTransform3D;

        AngleValue++;
    }

But then VS told me that "Input string was not in a correct format". Could anyone tell me how to do it?

More: I change my XAML code like: <AxisAngleRotation3D Axis="0,1,0" Angle="{Binding ElementName=Window1, Path=AngleValue}"/> But the photo is static (won't rotate at all)...

4

3 回答 3

0

You need to create AngleValue as a DependencyProperty, and use databinding in your XAML to bind to the value.

For an example of creating the binding, see my answer here.

<Window ... Name="MyWindow">
  <Grid>
    <AxisAngleRotation3D Axis="0,1,0" Angle="{Binding ElementName=MyWindow, Path=AngleValue}"/>
  </Grid>
</Window>

Alternatively, you can give your AxisAngleRotation3D object an x:Name property and change your angle directly from the code-behind.

于 2013-10-11T15:44:28.823 回答
0

你写:Angle="AngleValue" Angle必须是一个数字

于 2013-10-11T15:33:36.780 回答
0

XAML

<AxisAngleRotation3D x:Name="rotation" Axis="0,1,0" />

背后的代码

rotation.Angle++

注意:这是一种方法,但您还应该查看允许您使用XAML编写的MVVM 模式。Angle={Binding AngleValue}

于 2013-10-11T15:34:02.943 回答