It’s been hard work so far, but we’ve now done enough to ensure the required amount of trust exists for us to re-use our Wpf-User-Control in a browser. We will not have to do this work again just so long as we continue to use the same certificate (previously created) to sign our XBAP solutions.
 
If you cast your mind back… the Wpf-User-Control that I’m working on was originally designed for the Dynamics-windows-rich-client. Then I “ported” it to MS Excel and made it operate againt data selected within “active-cells”. I now want to integrate it with Enterprise Portal and set its context by using Url parameters. Each integration platform will always require some “wrapper-code” (the codeset of the UserControl remains unchanged).
 

·         The WpfBrowserApplication will be integrated into Sharepoint as an “external website webpart” (using Url query string parameters). For more information see here: [http://office.microsoft.com/en-gb/sharepoint-server-help/connect-a-query-string-url-filter-web-part-to-another-web-part-HA010250999.aspx]

 
The WpfBrowserApplication needs a “holding” page which will include the UserControl and some C# code-behind to initialise it. The amount of code required is small. Here is a sample:
 
Xaml
<Page x:Class="XEWpfBrowserApplication.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      mc:Ignorable="d"
      xmlns:XEInterop="clr-namespace:XEInterop;assembly=XEInterop"
      d:DesignHeight="500" d:DesignWidth="1025" Title="Page1">
    <StackPanel>
        <TextBlock FontSize="24" Foreground="#FF4B32F5" Padding="0,0,0,10">Sharepoint Webpart</TextBlock>
        <XEInterop:Startup x:Name="XEUserControl"></XEInterop:Startup>
    </StackPanel>
</Page>
 
Code-behind
namespace XEWpfBrowserApplication
{
    /// <summary>
    /// Interaction logic for Page1.xaml
    /// </summary>
    public partial class Page1 : Page
    {
        public Page1()
        {
            InitializeComponent();
 
            // initialise Wpf UserControl
            XEUserControl.ContextEnvironment = "WpfBrowserApplication";
            XEUserControl.ContextTable = "XETable";
            XEUserControl.ContextMode = "Create";
            XEUserControl.ShowDebug = false;
            XEUserControl.Logon();
 
            // if the xbap solution is running from Sharepoint then attempt to extract Url parameters
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                Uri launchUri = ApplicationDeployment.CurrentDeployment.ActivationUri;
                Int64 _contextRecId;
                if (Int64.TryParse(HttpUtility.ParseQueryString(launchUri.Query).Get("ContextRecId"), out _contextRecId))
                {
                    XEUserControl.ContextRecId = _contextRecId;
                    XEUserControl.Process();
                }
            }
        }
    }
}
 
 
When you look at the C# code-behind then you can see that the WpfBrowserApplication is looking for a “ContextRecId” to be supplied (to the UserControl) only if the application is served from a network location (i.e. the Sharepoint website). Theoretically, this could be any context parameter related to the Sharepoint page that you wish to integrate your UserControl into.
 
You need to ensure that your XBAP solution can accept Url parameters by setting the following options in the application manifest:

 

 

 

Compile and publish your XBAP solution.

 

 

 

We now need to test our XBAP solution. Fire up IE on one of the client machines (that you’ve previously installed the application certificate onto) and navigate to the site listed in the publish options above ( append “publish.htm” to the Url):

 

 

 

If this is the first time this application has run on this machine, then the user must accept the following security message (you won’t be challenged with this message again):

 

 

 

There is a small delay as the solution is downloaded from Sharepoint (for the first time).
 

·         Depending on the cache settings of your machine, subsequent download and execution times will be quicker.

 
As the XBAP application is designed to be used as a web-part then the rest of the Sharepoint page will load while the UserControl is initialising. The UserControl normally takes longer to initialise than standard HTML.
 

·         With XBAP solutions you won’t get the performance of rapid page loading (don’t forget this is not a web page; it’s an application that is being downloaded from a central location and executing within a browser).

 
When the XBAP solution loads, you should see it appear within the browser (it will have all the functionality of the UserControl that is presented within the Dynamics-windows-rich-client). In order to make the UserControl react to a context change you will need to set the query parameter on the webpart Url. The UserControl should read the query parameter and initialise itself. Once successfully tested, your UserControl is ready to be integrated into one of the Enterprise Portal pages. This should now be a straightforward exercise for you Sharepoint specialists out there!
 
The following YouTube video illustrates the principles being discussed above: [http://youtu.be/Wkg-z3GKkMs?hd=1]
 
GOOD LUCK
 
 
 
 
FOR REFERENCE
 
XBAP solutions need access to external resources (like query string parameters) and you will need to incude a reference to the application deployment assembly. More information can be found here: http://msdn.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.aspx