1

我是 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);

        }

    }
}
4

0 回答 0