Over a million developers have joined DZone.

Things to consider when building a browser-based WPF application

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

Although WPF browser-based applications are not that popular with the growing interest in Silverlight, HTML5 and JavaScript (yes, I said JS), those still have a niche due to the capabilities offered by them. Not many developers know that the advantage of XBAP (WPF browser-based) applications is the fact that it is possible to directly invoke OS calls from the application that runs in the browser. Although with great power comes great responsibility, it is very possible to use XBAP apps in a much broader context compared to standard Silverlight applications.

So here are some points to remember when developing XBAP applications.

Full trust apps will require a certificate

In order to be able to access the OS capabilities (even components like the WebBrowser) will require the application to have a certificate installed on every client machine. This is not that big of an issue if the application is used internally, where people can set a specific security level and installing an internal certificate is not a problem. For external applications, users might be a bit hesitant if the certificate comes outside the trusted zone.

The default certificate that is assigned to an application will not be enough because it is assigned to a test machine and will only work for a short period of time. The solution here is to generate your own certificate and make it available to users who will use the app. Instructions on how to do this are available here.

Make sure that you re-size the application properly

When the application runs inside the browser, you never know what size it will have. That being said, implement  a simple re-sizing mechanism. For example, in one of the applications I was working on I did this:

  • The Page (content host) has no explicit size limits defined.
  • Using a Canvas control instead of the default Grid to define the page layout.
  • When the page is resized, I am handling this in the SizeChanged event handler:
this.SizeChanged += new SizeChangedEventHandler(Page1_SizeChanged);

The internals of the event handler look like this:

void Page1_SizeChanged(object sender, SizeChangedEventArgs e)
{
    WHost.Height = this.ActualHeight;
    WHost.Width = this.ActualWidth;
}

Here, WHost is a control inside the Canvas.

Be ready for deployment nuances

This is mainly tied to the fact that deployment is done through ClickOnce. Also, another important requirement for an XBAP application is the presence of .NET Framework 3.0 on the client machine. This might become a serious roadblock on *nix and Mac machines. That being said, Silverlight is less restrictive in this context, but some features will be removed (e.g. native access to the OS).

IE doesn't "like" XBAP applications by default. Other browsers - not so much, either.

In Internet Explorer 9, by default XAML Browser Applications are disabled.

To enable this, the user will have to edit Internet Zone settings. From my own experience I can say that not a lot of users will take this step, and this might be the deciding factor whether to use the XBAP app or not.

Speaking of other browsers, most of them will try to download the XBAP file (which can be subsequently opened in IE), but this will ultimately cause problems since there are applications that rely on the source URI scheme.

Conclusion

The conclusion here is very subjective, but I would say that XBAP applications should only be used when it comes to an application targeting a very specific group of users (e.g. in a company or department). An attempt to scale it to a larger audience will result in more frustration given some restrictions imposed by the sandbox on deploying (less on actually running it). The default choice for RIA that run in a browser (in the .NET stack) should be Silverlight - that's only if you don't need access to most system features (some limited interop is present in Silverlight via COM).

The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.

Topics:
dotnet ,opinion ,silverlight ,visual studio ,wpf ,xaml ,xbap

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}