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;

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

Tagged on: , , , ,

14 thoughts on “3D Full Screen Window and Dynamic XAML Sample with WPF

  1. Mohit Batra

    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!!!

  2. Ankit

    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.

  3. Mohit Batra

    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!!!

  4. 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.

  5. Ankit

    Hey Shivay…

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

    The post targets to those ppl having Programming knowledge..

  6. 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

  7. Jens


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


    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

  8. 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 ?


Leave a Reply

Your email address will not be published. Required fields are marked *