2017-03-09 75 views
2

所以我有這樣的XAML代碼在我的「視圖」組件:WPF Helix如何在代碼中「縮放範圍」viewport3d?

<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這創造了新的陰謀(顯示某些點,boundarybox,標籤等

):

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()因爲我沒有任何參考螺旋:HelixViewport3D在我的XAML聲明

回答

0

我只是說事件對我ScatterPlotVisual3D和XAML分配了此事件的看法私有函數,它可以訪問HelixViewport3D並在其上調用ZoomExtents()。現在,我在加載我的數據時致電我的活動

1

您可以通過在XAML分配一個名稱創建C#代碼到Helixviewport參考:

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

然後在C#代碼,只需調用下面的孩子已被更新後。

NameYouChoose.ZoomExtents()