views:

511

answers:

1

I created a silverlight app (without website) named TestApp, with one TextBox:

<UserControl x:Class="TestApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Grid x:Name="LayoutRoot">
        <TextBlock Text="this is a test"/>
  </Grid>
</UserControl>

I press F5 and see "this is a test" in my browser (firefox).

I select File | Export Template | name it TestAppTemplate and save it.

I create a new silverlight app based on the above template.

The MainPage.xaml has the exact same XAML as above.

I press F5 and see a blank screen in my browser.

I look at the HTML source of both of these and they are identical.

Everything I have compared in both projects is identical.

What do I have to do so that a Silverlight application which is created from my exported template does not show a blank screen?

(creating a WPF application from an exported template like this works fine)

+1  A: 

The Export Template tool does not understand the <XapFilename> and <SilverlightAppEntry> project properties. Hence when creating a template it does not place a replacement marker in either of these properties.

If you look in the bin\debug folder of the project you created from the template you will see that the Xap file has the same name as the source project from which you created the template not the name of the new project you created. That in itself isn't so much of a problem however inside you will find that the application entry point also uses the original namespace for the template source project. Yet the actual app entry point is correctly placed in the namespace of the new project. The entry point cannot be found when the test page loads the Xap into the plugin. In IE with debugging turned on you get an error dialog, in Firefox I suspect there is something in the error console if you open it up.

How to fix

First of all when creating the template don't let VS automatically import it (its only only a file copy anyway).

Once the template is created find the template zip file in "Documents\Visual Studio 2008\My Exported Templates" folder. Extract the .csproj file.

Modify the <XapFilename> property to:-

<XapFilename>$safeprojectname$.xap</XapFilename>

and the <SilverlightAppEntry> property to:-

<SilverlightAppEntry>$safeprojectname$.App</SilverlightAppEntry>

put the .csproj back in the Zip file.

Now you can copy the Zip file to a "Documents\Visual Studio 2008\Templates\Project Templates\Visual C#\Silverlight" folder.

The template should appear when you select Visual C#\Silverlight in the new project dialog.

Create a project and it should run correctly with F5.

AnthonyWJones
Excellent, that was exactly it. I got tripped up a bit creating my zip file: I was zipping (with 7zip) the *directory* inside the zip file which was making Visual Studio not recognize it as a template. Just have to make sure you zip the *files* directly into the zip file. Good fix, thanks.
Edward Tanguay
@Edward: Yes I get caught out by that myself, its shame that Windows own Extract Zip and Send To Zip aren't symetrical either.
AnthonyWJones