2012-10-09 102 views
0

我需要使用wpf應用程序繪製一個3D管道像圖像,並將其嵌入到wpf中的自定義控件中..i嘗試使用.xaml文件並繪製出像管道一樣的管道但我無法得到一個完整大小的正確圖像..可以幫助我如何做到..與圖形..使用WPF繪製3D管道

+0

什麼的.xaml你嘗試使用? –

回答

0

看看Helix Toolkit。它對wpf 3D有一些很好的控制,包括一個管道示例。

4

XAML:

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:ht="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" 
     Title="MainWindow" Height="350" Width="525"> 

    <Grid> 
     <ht:HelixViewport3D x:Name="MainViewPort"> 
      <ht:SunLight /> 
      <ht:GridLinesVisual3D/> 
     </ht:HelixViewport3D> 
    </Grid> 
</Window> 

後面的代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using HelixToolkit.Wpf; 
using System.Windows.Media.Media3D; 

namespace WpfApplication1 
{ 

    public partial class MainWindow : Window 
    { 

     public MainWindow() 
     { 
      InitializeComponent(); 
      DataContext = this; 
      DrawMeshes(); 
     } 

     private void DrawMeshes() 
     { 
      int tubeDiameter = 15; 

      TubeVisual3D tube1 = new TubeVisual3D(); 
      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); 
     } 
    } 
}