WPF Helix 如何在代码中实现“缩放”Viewport3D?

3

我有一个位于我的“视图”程序集中的XAML代码:

<helix:HelixViewport3D ZoomExtentsWhenLoaded="True"
                       ShowCoordinateSystem="True"
                       IsMoveEnabled="False"
                       Margin="5,5,5,0">
    <helix:HelixViewport3D.Camera>
        <OrthographicCamera LookDirection="1,1,-1" 
                            Position="{Binding CameraPosition}"
                            UpDirection="0,0,1">
        </OrthographicCamera>
    </helix:HelixViewport3D.Camera>
    <ModelVisual3D Content="{Binding Lights}"/>
    <local:ScatterPlotVisual3D Points="{Binding Data}"
                               SolutionPoints="{Binding Solution}"
                               SurfaceBrush="{Binding SurfaceBrush}"/>
</helix:HelixViewport3D>

在“视图模型”程序集中,我正在将一些数据加载到ScatterPlotVisual3D中,它会创建新的绘图(显示一些点、边界框、标签等):

private Model3D CreateModel()
{
    var plotModel = new Model3DGroup();
    if (Points == null && SolutionPoints == null) return plotModel;

    List<Point3D> allPoints = new List<Point3D>();

    if (Points != null && Points.Length != 0)
    {
        plotModel.Children.Add(CreatePointsModel(Points, Brushes.Green));
        allPoints.AddRange(Points);
    }

    if (SolutionPoints != null && SolutionPoints.Length != 0)
    {
        plotModel.Children.Add(CreatePointsModel(SolutionPoints, Brushes.Red));
        allPoints.AddRange(SolutionPoints);
    }

    CreateBoundaryAxis(plotModel, allPoints);            

    return plotModel;            
}

我的需要是在加载数据时强制 HelixViewport3D 执行 ZoomExtents()(或任何其他类似的缩放相机以适应模型的方式)。


问题:我无法调用 ZoomExtents(),因为我在 XAML 中没有对 helix:HelixViewport3D 的引用声明。

2个回答

4

您可以通过在XAML中给HelixViewport分配一个名称来在C#代码中创建对其的引用:

<helix:HelixViewport3D Name="NameYouChoose"
                       ZoomExtentsWhenLoaded="True"
                       ShowCoordinateSystem="True"
                       IsMoveEnabled="False"
                       Margin="5,5,5,0">

在C#代码中,仅在子元素更新后调用以下内容。
NameYouChoose.ZoomExtents()

0
我刚刚在我的ScatterPlotVisual3D中添加了事件,并在xaml中将此事件分配给视图的私有函数,该函数可以访问HelixViewport3D并在其上调用ZoomExtents()。现在当我加载数据时,我调用我的事件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接