Register  Login
Blog
Silverlight Desktop Blog
Jun 21

Written by: Michael Washington
6/21/2008 6:48 AM

Now that we have SilverlightDesktop working again we are now creating modules for it.

The first problem we ran into was that we had to remove the .dll from the .xap and place the .dll in the /Clientbin directory.

When you are constantly building your project and testing it, this gets old really fast. We realized we have to allow you to keep the assembly in the .xap and allow you to load it from there.

This is the new code we are using:

#region Load Assembly
        void proxy_GetDesktopModuleCompleted(object sender, GetDesktopModuleCompletedEventArgs e)
        {
            objSilverlightDesktopModule = (SilverlightDesktopModule)e.Result;
 
            strXAPName = objSilverlightDesktopModule.AssemblyName;
            strAssemblyClassName = objSilverlightDesktopModule.ClassName;
            StartDownloader();
        }
 
        private void StartDownloader()
        {
            WebClient downloader = new WebClient();
            downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
            downloader.OpenReadAsync(new Uri(strXAPName, UriKind.Relative));
        }
 
        void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            loadAssembly(e.Result);
        }
 
        private void loadAssembly(Stream s)
        {
            // from http://silverlight.net/forums/p/14941/49437.aspx (BlueAquarius)
            // From http://joel.neubeck.net/2008/03/silverlight-how-to-on-demand-assembly-deployment/
  
            try
            {
                Uri uri = new Uri(strXAPName.Replace(".xap", ".dll"), UriKind.Relative);
                StreamResourceInfo xapPackageSri = new StreamResourceInfo(s, null);
                StreamResourceInfo assemblySri = Application.GetResourceStream(xapPackageSri, uri);
 
                AssemblyPart assemblyPart = new AssemblyPart();
                Assembly a = assemblyPart.Load(assemblySri.Stream);
 
                UserControl objUserControl = (UserControl)a.CreateInstance(strAssemblyClassName);
                if (objUserControl == null)
                {
                    debug("objUserControl is null");
                    return;
                }
 
                SilverlightWindowControl objSilverlightWindowControl =
new SilverlightWindowControl(objSilverlightDesktopModule.WindowSize);
                objSilverlightWindowControl.Window.Content = objUserControl;
                objSilverlightWindowControl.WindowName.Text = objSilverlightDesktopModule.ModuleName;
                intWindowLocation = intWindowLocation + 10;
                Canvas.SetLeft(objSilverlightWindowControl, (double)intWindowLocation);
                Canvas.SetTop(objSilverlightWindowControl, (double)intWindowLocation);
 
                this.LayoutRoot.Children.Add(objSilverlightWindowControl);
            }
            catch (Exception ex)
            {
                debug("Exception when loading the assembly part:");
                debug(ex.ToString());
            }
        }
        #endregion

Tags:
  

Terms Of Use | Privacy Statement | Copyright 2008 by SilverlightDesktop.net Dynnamite DotNetNuke Skins & Modules