XBAPs Part 1: An introduction to this Gem
XBAPs Part 1: An introduction to this Gem
Join the DZone community and get the full member experience.Join For Free
XBAPs (XAML Browser Application) are a really cool feature that was introduced in .NET 3.0 together with WPF. Well you can say that XBAPs are as such part of WPF because at the end of the day XBAPs are just WPF applications that can run inside the browser. One important thing to state here is that XBAPs and Silverlight have nothing to do with each other. XBAPs are full .NET enabled WPF applications, while Silverlight is a “cut down version of WPF” that runs as a browser plugin. In order to run a Silverlight enabled website you need to download the Silverlight installer(that is really really small approx 4.3 MB), if you want a client to run a XBAP the client has to have .NET installed on his machine (the Full .NET or Client Profile).
Before we continue I would like to point out that this post is just an introduction to XBAPs. I will have Part 2, Part 3 and Part x that should be much more interesting to follow…. Yet if you never heard of XBAPs you should continue reading this post (and try not to fall asleep ).
What does your Client need?
As I said above, in order for a client to run your XBAP he/she needs to have .NET framework installed. It’s as if the client is going to run a Windows application. XBAPs got a set of improvements in .NET 3.5 such as support for Firefox (read more here) and also support for consuming WCF service in partial trust mode (with some limitations of course but still it’s good, read more here). So yea if you are planning on using XBAP’s I would seriously consider .NET 3.5.
To summarize your Client needs to have .NET installed and he can use the XBAP in Internet Explorer or if he prefers (and you are using .NET 3.5) Firefox.
Some things to keep in mind …
XBAPs run in the browser and give an impression of being a normal website (super cool website I must say ) while instead they are just actual apps that never jump out of the browser, yet there is more to it… XBAP’s run in a “sandbox”, basically they run as Partial Trust by default. What this means is that some of the things that you would assume would work in a WPF app would not work in an XBAP, for example Reflection (and also the new 3.5 SP1 feature Effects ). Of course there are workarounds. You can run XBAPs as Full trust mode and we will discuss how to later on in this article.
Building a simple XBAP
So let’s start having a look at how one can build an XBAP. In order to create a new XBAP project you have to do the usual stuff, so go to File > New > Project and select WPF Browser Application
Now that we created the project, let’s have a look at what Visual Studio created for us
So as you can see by default Visual Studio created more or less the same stuff it would have created for a WPF Application yet instead of using a Window it created a Page. This is very important because a Page was designed for Navigation (the back and forward button of the browser). I will discuss Navigation more later on in this article. Besides this Visual Studio also created a pfx file. The pfx file is a way how to sign the exe, by default Visual Studio creates a pfx file that it uses to sign the Click once installer for the XBAP.
The image above shows how Visual Studio generated that pfx file. Please not that there is the Computer name and username inside the pfx files (which obviously is not something you want to give to your client). Charles Perzold discusses this in more detail here.
Ok so now that we know what Visual Studio created for us (thanks VS we love you) we can test our XBAP app (yea we can already run it ). In order to see something on screen lets just create a button in the Page1.xaml and press F5 to run.
<Button Content="My First XBAP :) " Height="50" Width="150"/>
Yahhooo we have everything figured out don’t we well there are a couple of other things we need to have a look at.
If you are a WPF developer you will be developing XBAP in no time. There are a couple of things you must keep in mind, like Code Access Security and other tricks like how to consume WCF service…. In my next posts I will cover these things and make sure that I pass on my knowledge (knowledge that came from a lot of frustration and hours of head banging on the table).
Published at DZone with permission of Marlon Grech . See the original article here.
Opinions expressed by DZone contributors are their own.