Skip to content

3D Full Screen Window and Dynamic XAML Sample with WPF

 

One nice feature of WPF (Windows Presentation Foundation, .Net 3.0) is the integration of 3D library with the existing framework. Today I worked with Viewport3D class. This class handles it all for managing 3D views. The “Hello World” example I coded here basically demonstrates three features:

  • Loading XAML dynamically at runtime
  • Playing with 3D objects using Viewport3D and make them rotate using mouse.
  • Creating transparent and full-screen windows

Let’s drill down to the technical details of above three aspects:

Firstly, loading XAML runtime can be achieved using System.Windows.Markup.XamlReader class. The Load function takes a stream object (containing XAML source) and return appropriate UI control. Actually, it returns the root control in the stream.

FileStream fs = File.OpenRead(fileName);
this.view3D = (Viewport3D) System.Windows.Markup.XamlReader.Load(fs);

Secondly, the class Viewport3D does it all for you to handle 3D objects. Here we have just hooked mouse events that allows rotation of 3D object in all directions. Moreover you can zoom in/out using right mouse button. Thanks Daniel for writing TrackBall class.

Lastly, setting few parameters as below we can make a Window appear transparent and full-screened:

this.win = new Window();
win.Content = view3D;
win.ShowInTaskbar = false ;
win.Background = Brushes.Transparent ;
win.AllowsTransparency = true;
win.WindowStyle = WindowStyle.None ;
win.WindowStartupLocation = WindowStartupLocation.CenterScreen ;
win.WindowState = WindowState.Maximized;
win.Show();

Well, I guess that’s enough for the first WPF post.
Download the source code for sample application: Load-3D-XAML-Runtime.zip

Thanks for reading.
~ Ankit

14 Comments

  1. Very nice dude!!! I still have not downloaded the project because dont have .NET 3.0 installed on my machine yet. But its really nice to know about this that .NET has a support for 3D objects now. Just wondering, if that is for forms and all those stuff only or anything for game development as well. And also, will this 3D windows work on versions preceeeding Vista, like XP and 2003. Guess should be, but wont have that kind of effect, I think.

    Still a nice one. Will surely wait for the next post in this series :)

    And ya, do check out for SQL Object Model Support and the funda of Cards in .NET 3.0 – its new and interesting. Man!!! .NET is really evolving fast and I am loving it more and more!!!

    Posted on 02-Dec-06 at 2:55 am | Permalink
  2. Hey Mohit, basically they have specialized classes for creating 3D objects. You can use them on forms as well as in game development.

    Naturally, this will work where .Net 3.0 framework works. (Windows XP SP2 & Windows 2003 server)
    Actually Cards (CardSpace) is not a part of .Net 3.0 framework, it’s a Vista component.

    Posted on 02-Dec-06 at 6:41 pm | Permalink
  3. This is great to know that 3D objects can “really” be utilized for games. I am not a game developer but would certainly like to get rinsed with this domain.

    I agree that this will only work where .NET 3.0 is..but my point of concern was that .NET 3.0 must be utilizing OS functions for doing this stuff, how much can Windows XP and 2003 support? They have 3D support, but what is there in 3.0 that is more inclined towards future OS like Vista that these previous versions. Just think of this, that .NET 2.0 and lower versions can be installed on Windows 98 (certainly dont know about 3.0 and I have myself installed 1.1 on Win98, so took 2.0 as an assumption ;) )..so how much Win 98, ME and those OS can utilize out of this?

    And ya, thanks for clearing about CardSpace, but do check out for that SQL Object Model Support. Once I will get more information on this, I will let you know!!!

    Posted on 03-Dec-06 at 2:56 am | Permalink
  4. Update – CardSpace is a part of .NET 3.0 only. I just downlaoded 3.0 version, and read thru online documentation. Update your knowledge base buddy :)

    Posted on 15-Dec-06 at 11:18 am | Permalink
  5. but hey!
    you could have done same with the resource files :)

    Posted on 20-Dec-06 at 7:30 pm | Permalink
  6. Yup, but the idea is to show how to load Xaml from file system, and may be any other source.

    Posted on 20-Dec-06 at 7:57 pm | Permalink
  7. shivam verma

    please start from initial,as most of the visitors r beginers.
    like go on start type \’this\’ then do \’this\’.
    or go in \’this\’ directory n there type \’this\’ n then run the new code from \’here\’.
    coz nearly 80% was a bouncer to me,
    n yes i m a beginer.

    Posted on 30-Mar-07 at 2:33 am | Permalink
  8. Hey Shivay…

    Btw, it’s not possible for me to write in so details…

    The post targets to those ppl having Programming knowledge..

    Posted on 30-Mar-07 at 9:07 pm | Permalink
  9. madhu

    Hi ankit, its nice sample,

    as i am new to WPF, can you help me out how can i generate the house.xaml, heliCoptor.xaml, ffg_fournel.xaml, enterprice.xaml files.

    i have ascenario where i need to generate a UI window at runtime by using a component (.dll), then i need to show that UI from WPF application. the typical requirement of the UI is with regular controls like textbox,button and some mthods to DataBase

    hope u can help on this

    Posted on 20-Apr-07 at 9:15 pm | Permalink
  10. Hi Madhu,

    try searching “3d to XAML” in Google. There are Zam3d, Maya to XAML tools available and can help u.

    Posted on 21-Apr-07 at 1:39 am | Permalink
  11. Jens

    Hi

    Thanks for a great article…..
    But the xaml for testing purposes in your solution is not included ?

    (“enterprice.xaml”);
    (“house.xaml”);
    (“ffg_fournel.xaml”);
    (“heliCoptor.xaml”);
    (“CSSNA140.xaml”);

    could you please upload these files so your solution comes to the full extend of its purpose.

    That way i am able to give you the credits and recommendation as derserved.

    Kind regards
    Jens

    Posted on 01-Nov-07 at 7:22 pm | Permalink
  12. vaibhav

    hi ankit,

    i am a student of information and interface design with fine arts background and currently working on a project using wpf. therefore not comfortable with coding etc. I downloaded your zip file but still i cant see codes for viewing my 3d object in testsolution window in blend 2 using mouse for zoom and pan. Can you help me regarding this ?

    regards
    vaibhav

    Posted on 15-Mar-09 at 4:53 pm | Permalink
  13. Hossein

    Hello
    I can’t append a new model to my environment
    How do I?

    thanks

    Posted on 29-Mar-09 at 2:24 pm | Permalink
  14. roriron

    Thanks!!!!

    Posted on 27-Oct-09 at 9:41 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word