none
Converting WPF Desktop app to XBAP

    Question

  • I'm pretty well underway in creating a WPF desktop application.  I'm starting to think about what I need to do to convert it to an XBAP in partial trust (I want to run it in both ways).  I have a few questions:

     

    1. How do I start? From Visual Studio 2008 should I create an XBAP project and move the files over, or should I use the VS template from Scorbs.com?  I believe that it doesn't currently support publishing, which may be a problem for me.

     

    I need to convert my modal dialogs to popups, luckily my dialogs are transparent and have no chrome (i.e. the XAML defines the look),

     

    2. How can I most easily use my existing dialog XAML in a popup?

     

    3. Do I need to simulate the modal feature by disabling my interface?

     

    4. Any other diffences between popups and modal dialogs that I need to take into account?

     

    Many of these dialogs are essentially file browsers (browse directories for specific file types e.g. .jpg).  Now these files/directories will be on the server.

     

    5. Is there any sample code for browsing/downloading files on a server from an XBAP? Or what are the important methods to look at?

     

    6. Is there any sample code for uploading local files to the server? Or what are the important methods to look at?

     

    7. Is there any sample code for uploading files created by the XBAP application (i.e. bitmaps created from visuals) to the server. Or what are the important methods to look at?

     

    Any other suggestions/comments are welcome.

     

    Thanks

    Tom

     

    Tuesday, December 18, 2007 6:13 PM

Answers

  • Lots of people ask about making hybrid apps... what I'd suggest is to simply create two projects and have a common code folder for any code that can be run by either application.  You can't have full trusted objects in an assembly being executed in partial trust, even if they are never used or called.  This can be confusing but is a primary reason why the hybrid project type is not sustainable.  Further, the debugging / compilation process for the two kinds of apps has changed since Charles and Karen wrote their respective articles... changing between project types can cause debug and build headaches.

     

    That said, here's some answers to your other questions:

     

    2. How can I most easily use my existing dialog XAML in a popup?

     

    Create a class that derives from popup, and simply load the existing XAML into a ContentPresenter object inside the popup.  Make sure the popup draws within your partial trust app's area.

     

    3. Do I need to simulate the modal feature by disabling my interface?

     

    Yes, when you are making "fake" dialogs, you must handle modality (if you want it)

     

    4. Any other diffences between popups and modal dialogs that I need to take into account?

     

    None I can think of that havent already been mentioned...

     

    5. Is there any sample code for browsing/downloading files on a server from an XBAP? Or what are the important methods to look at?

     

    Not that I know of.  However, your app likely won't be able to arbitrarily browse the contents of your server.  Most likely you will need a webservice hosted on the same site as your .xbap that performs server file-browsing functions for you.

     

    6. Is there any sample code for uploading local files to the server? Or what are the important methods to look at?

     

    From partial trust you may access the File Open dialog, which will expose a stream.  Response to #5 most likely applies here as well... you can get the filestream easily but may need to use a web service to get it ON the server.

     

    7. Is there any sample code for uploading files created by the XBAP application (i.e. bitmaps created from visuals) to the server. Or what are the important methods to look at?

     

    This would be much like #6, except you would want to first write your created files to a memory stream (to avoid the 512 K isolated storage limit), then pass this stream to your "server uploading" web service.


    HTH,

    Matt

     

    Thursday, December 20, 2007 5:56 PM

All replies

  • Update...

     

    This article by Charles Petzold answers part of question #1 for VS 2005.  Does VS 2008 make these steps any easier or different?  In other words does VS 2008 make it easier to switch between EXE and XBAP?

     

    http://www.charlespetzold.com/blog/2006/11/120718.html

     

    BTW, I failed to mention that my current server environment is Linux/PHP based, I don't know if that effects the answers.  I could look into changing to Windows/ASP based if necessary.

     

    Thanks

    Tom

     

     

    Wednesday, December 19, 2007 5:59 PM
  • Lots of people ask about making hybrid apps... what I'd suggest is to simply create two projects and have a common code folder for any code that can be run by either application.  You can't have full trusted objects in an assembly being executed in partial trust, even if they are never used or called.  This can be confusing but is a primary reason why the hybrid project type is not sustainable.  Further, the debugging / compilation process for the two kinds of apps has changed since Charles and Karen wrote their respective articles... changing between project types can cause debug and build headaches.

     

    That said, here's some answers to your other questions:

     

    2. How can I most easily use my existing dialog XAML in a popup?

     

    Create a class that derives from popup, and simply load the existing XAML into a ContentPresenter object inside the popup.  Make sure the popup draws within your partial trust app's area.

     

    3. Do I need to simulate the modal feature by disabling my interface?

     

    Yes, when you are making "fake" dialogs, you must handle modality (if you want it)

     

    4. Any other diffences between popups and modal dialogs that I need to take into account?

     

    None I can think of that havent already been mentioned...

     

    5. Is there any sample code for browsing/downloading files on a server from an XBAP? Or what are the important methods to look at?

     

    Not that I know of.  However, your app likely won't be able to arbitrarily browse the contents of your server.  Most likely you will need a webservice hosted on the same site as your .xbap that performs server file-browsing functions for you.

     

    6. Is there any sample code for uploading local files to the server? Or what are the important methods to look at?

     

    From partial trust you may access the File Open dialog, which will expose a stream.  Response to #5 most likely applies here as well... you can get the filestream easily but may need to use a web service to get it ON the server.

     

    7. Is there any sample code for uploading files created by the XBAP application (i.e. bitmaps created from visuals) to the server. Or what are the important methods to look at?

     

    This would be much like #6, except you would want to first write your created files to a memory stream (to avoid the 512 K isolated storage limit), then pass this stream to your "server uploading" web service.


    HTH,

    Matt

     

    Thursday, December 20, 2007 5:56 PM
  • We are successfully deploying our application both as a ClickOnce and as an XBAP application. 99% of the code (incl. xaml) is done in assemblies, leaving only configuration issues to the project files that contain the application components.

     

    You do have to plan for the smallest common denominator (partial trust), but you are of course free to include code that requires full trust in assemblies that are only referenced in the ClickOnce/standard application.

     

    We discussed some of these issues in a thread earlier this year. See here for more: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1964599&SiteID=1.

     

    Hope this helps,

    Tor.

     

    ------

    Tor Langlo

    Koda Software

    Web: http://www.kodasoftware.com

    Blog: http://torlanglo.spaces.live.com

     

    Thursday, December 20, 2007 7:02 PM