Recommended Project Template Modifications

As you've seen, you get quite a reasonable starting point for a business application in Silverlight, but you'll probably want to make a few changes to the default template before you get started developing.

As described previously, the following files can be found in the web application project in your solution:

  • ApplicationNameTestPage.aspx
  • ApplicationNameTestPage.html

These two pages do much the same thing—there's little difference (in terms of results) between the two, so you only really need one of them. ASPX pages need to be processed on the server by ASP.NET, so unless you want to do some processing in the code-behind of the page (such as checking security credentials), you can simply use the HTML page instead. You can then delete the one you don't need. On the remaining page, right-click its entry in Solution Explorer, and select Set as Start Page from the context menu to ensure it is automatically loaded in the browser when the project is run.

When you run the Silverlight project, you might expect the Silverlight application to have the focus, but actually, the web page has the focus. Therefore, if the starting page in your application has a text box with the focus explicitly set to it when the page is loaded, you will see some strange behavior. The text box may not have focus automatically, or it might have focus but not show the blinking caret. We can resolve this issue by adding a little bit of JavaScript code to the web page.

Open the HTML page to inspect its contents (in Source view). Add the following code directly below the onSilverlightError JavaScript function at the top of the page:

function appLoad(sender, args)
{
    var xamlObject = document.getElementById('silverlightControl'),

    if (xamlObject != null)
        xamlObject.focus();
}

Add this property to the Silverlight object tag:

id="silverlightControl"

And add the following line to the properties of the Silverlight object:

<param name="onLoad" value="appLoad" />

Run the project again, and you will find that the text box now correctly has the focus. You can see the caret blinking, and typing (without clicking the application first) will populate the text box with the typed characters.

images Note If the change doesn't seem to have worked, try refreshing the page using Ctrl+F5; the page may have been cached and not updated with the changes made.

At this stage, you might want to also add the following property to the Silverlight object:

<param name="Windowless" value="True" />

The purpose of this will be discussed in Chapter 15, where it is necessary in order to overlay the application with an IFrame to display reports. There are performance impacts to setting this property to True, but as most business applications aren't graphicly intensive, this should not be too much of an issue. You are now ready to start working on your Silverlight project.

In the Silverlight project, open the ApplicationStrings.resx file (under the AssetsResources folder). Find the ApplicationName resource, and change its value to the name of your application. This name will appear in the header of the application when you run it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset