WPF with Helix toolkit, animate with code-behind?

邮差的信 提交于 2021-01-29 02:49:36

问题


I am new to WPF, and am trying to build a 3d viewport with helix toolkit. The viewport, grid etc show up as expected, And I add a simple tube. Now, i want to use a new function to update the Transform of the tube, based on user input, but I cannot get it to work.

Where am i going wrong here?

Thank you.

.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);

        }

    }
}

来源:https://stackoverflow.com/questions/38511647/wpf-with-helix-toolkit-animate-with-code-behind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!