Eyeshot 11 Documentation
WPF Control / Quick Start
In This Topic
    Quick Start
    In This Topic

    This topic will give you a head start on creating great looking viewport for all of your WPF applications.

     Creating a new WPF Project
    1. Launch Visual Studio
    2. From the File menu, select New, and then click Project
    3. In the New Project dialog box, click either Visual C# or Visual Basic from the Project types list
    4. From the Templates list, click WPF Application
    5. In the Name field, replace the default project name with the name of your project
     Adding the control to your MainWindow

    Add the control to your MainWindow by either double-clicking on the ViewportLayout toolbox icon (installed in the 'Eyeshot Ultimate 11' tab of the Visual Studio toolbox), or by clicking on the icon once then "drawing" the control onto the form using the left mouse button. Choose the layout from the Preset Manager and click Load.

    Figure 1: The ViewportLayout control in design-time mode.

     Naming the ViewportLayout control

    In the MainWindow XAML editor, add the "viewportLayout1" name to the ViewportLayout control.

    Figure 2: Adding a name to the WPF control.

     Required using/Imports statements

    Add the following using/Imports statements at the beginning of the MainWindow.xaml.cs file.

    using devDept.Eyeshot;
    using devDept.Eyeshot.Entities;
    using devDept.Geometry
    Imports devDept.Eyeshot
    Imports devDept.Eyeshot.Entities
    Imports devDept.Geometry
     Customizing the Viewport

    Change the coordinate system icon Z arrow color setting the Lighting property as false and changing the ArrowColorZ property.

    Your first 3D drawing with Eyeshot

    Figure 3: Customizing coordinate system icon from XAML.

     Drawing a box

    Add the following OnContentRendered() override, then build and start your application.

    protected override void OnContentRendered(EventArgs e)
    {
       // Creates a mesh with the shape of a box
       Mesh m = Mesh.CreateBox(30, 20, 10);
    
       // Adds the mesh to the master entity collection
       viewportLayout1.Entities.Add(m, System.Drawing.Color.DarkRed);
    
       // Fits the drawing in the viewport
       viewportLayout1.ZoomFit();
    
       // Redraw the control
       viewportLayout1.Invalidate();
    
       base.OnContentRendered(e);
    }
    Protected Overrides Sub OnContentRendered(e As EventArgs)
       ' Creates a mesh with the shape of a box
       Dim m As Mesh = Mesh.CreateBox(30, 20, 10)
    
       ' Adds the mesh to the master entity collection
       viewportLayout1.Entities.Add(m, System.Drawing.Color.DarkRed)
    
       ' Fits the drawing in the viewport
       viewportLayout1.ZoomFit()
    
       ' Redraw the control
       viewportLayout1.Invalidate()
    
       MyBase.OnContentRendered(e)
    
    End Sub

    You should now see something like this:

    Your first 3D drawing with Eyeshot

    Figure 3: Your first 3D drawing with Eyeshot.

    Navigation quick commands:

    • Middle mouse button combined with Ctrl or Shift keys to Zoom/Pan/Rotate
    • Mouse wheel to Zoom
    • Ctrl+F to fit the model in the viewport
     Now it's your turn

    Try adding add more entities like lines, circles, etc. You'll find them in the devDept.Eyeshot.Entities namespace.

    Under some circumstances you may prefer to handle InitializeScene event. This prevents a redundant viewport refresh at startup and doesn't need the closing ViewportLayout.Invalidate() call.

    public partial class MainWindow : Window
    {
       public MainWindow()
       {
          InitializeComponent();
    
          viewportLayout1.Unlock("UF1-XXXX-XXXXX-XXXXX-XXXXX");
    
          viewportLayout1.InitializeScene += new EventHandler(viewportLayout1_InitializeScene);
       }
    }
    
    private void viewportLayout1_InitializeScene(object sender, EventArgs e)
    {
       // Creates a mesh with the shape of a box
       Mesh m = Mesh.CreateBox(30, 20, 10);
    
       // Adds the mesh to the master entity collection
       viewportLayout1.Entities.Add(m, System.Drawing.Color.DarkRed);
    
       // Fits the drawing in the viewport
       viewportLayout1.ZoomFit();
    }
    Public Partial Class MainWindow
       Inherits Window
    
       Public Sub New()
    
          InitializeComponent()
    
          viewportLayout1.Unlock("UF1-XXXX-XXXXX-XXXXX-XXXXX")
    
          viewportLayout1.InitializeScene += New EventHandler(AddressOf viewportLayout1_InitializeScene)
    
       End Sub
    
    End Class
    
    Private Sub viewportLayout1_InitializeScene(sender As Object, e As EventArgs)
       ' Creates a mesh with the shape of a box
       Dim m As Mesh = Mesh.CreateBox(30, 20, 10)
    
       ' Adds the mesh to the master entity collection
       viewportLayout1.Entities.Add(m, System.Drawing.Color.DarkRed)
    
       ' Fits the drawing in the viewport
       viewportLayout1.ZoomFit()
    
    End Sub
    See Also