使用Helix工具包的WPF,使用代码隐藏动画?

时间:2016-07-21 18:20:01

标签: c# wpf xaml helix-3d-toolkit

我是WPF的新手,我正在尝试使用helix工具包构建一个3d视口。 视口,网格等按预期显示,我添加了一个简单的管。现在,我想使用一个新函数来根据用户输入更新管的转换,但我无法让它工作。

我在哪里错了?

谢谢。

的.xaml

  <UserControl x:Class="WPFUserControl.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" 
             mc:Ignorable="d"
             d:DesignHeight="480" d:DesignWidth="640">
    <Grid>
        <!-- The HelixViewport3D supports camera manipulation, and can be used just like the Viewport3D -->
        <HelixToolkit:HelixViewport3D ZoomExtentsWhenLoaded="True" Name="MainViewPort">

            <HelixToolkit:SunLight/>

            <ModelVisual3D Content="{Binding Model}"/>

            <HelixToolkit:GridLinesVisual3D Width="40" Length="40" MinorDistance="1" MajorDistance="1" Thickness="0.01"/>

        </HelixToolkit:HelixViewport3D>
    </Grid>
</UserControl>

.xaml.cs

using HelixToolkit.Wpf;

namespace WPFUserControl
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public TubeVisual3D tube1 = new TubeVisual3D();

        public UserControl1()
        {

            InitializeComponent();
            DataContext = this;
            Setup();

        }


        public void SetTranslation(double xx) //this is called from an external app.
        {

             Console.Write(xx); //This prints as expected.

            //TranslateTransform3D Trans = new TranslateTransform3D(new Vector3D(xx, 0, 0));     
          //  tube1.Transform = Trans;  //this does not work.

        }

        public void Setup()
        {             
            int tubeDiameter = 5;
            tube1.Path = new Point3DCollection();
            tube1.Path.Add(new Point3D(-15, 0, 0));
            tube1.Path.Add(new Point3D(15, 0, 0));
            tube1.Diameter = tubeDiameter;
            tube1.Fill = Brushes.Red;
            tube1.IsPathClosed = false;

            MainViewPort.Children.Add(tube1);

        }

    }
}

0 个答案:

没有答案