Even a chimp can write code

Friday, May 19, 2006

Passing URL parameters to a WPF browser application

A colleague asked:
I have a task on my plate to change the StartURI for our app based on query parameters to the xbap app. Is that possible?

We have one app (which combines Foo and Bar), but when users launch "myapp.xbap?view=Bar", I’d like to show a different initial UI.

[ed: minor edits made to the quote above to remove specificity]

So, can you pass in URL parameters to a WPF browser application (.XBAP)? Sure you can. However, only if the XBAP is deployed over HTTP. You cannot launch an app from a UNC share and expect to pass it HTTP request parameters.

Here's how: You need to specify <TrustUrlParameters>true</TrustUrlParameters> in the project file and use System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri property to get to the URL and pull the request parameters from it.

This functionality will not be available when you run the app within Visual Studio (i.e. hitting F5 or Ctrl-F5) because WPF applications launched from within Visual Studio are not ClickOnce-deployed.


Email this | Bookmark this


Post a Comment | Home | Inference: my personal blog