Click here to Skip to main content
Click here to Skip to main content

Tagged as

Part 4 of 4 : Tips/Tricks for Silverlight Developers

, 24 Dec 2010
Rate this:
Please Sign up or sign in to vote.
Part 4 of a series of blog posts that get right to the point and is aimed specifically at Silverlight Developers.

Part 1 | Part 2 | Part 3 | Part 4

I wanted to create a series of blog posts that get right to the point and is aimed specifically at Silverlight Developers. The most important things I want this series to answer is:

  • What is it?
  • Why do I care?
  • How do I do it?

I hope that you enjoy this series. Let’s get started:

Tip/Trick #16)

What is it? Find out version information about Silverlight and which WebKit it is using by going to http://issilverlightinstalled.com/scriptverify/.

Why do I care? I’ve had those users that it's just easier to give them a site and say copy/paste the line that says User Agent in order to troubleshoot a Silverlight problem. I’ve also been debugging my own Silverlight applications and needed an easy way to determine if the plugin is disabled or not.

How do I do it: Simply navigate to http://issilverlightinstalled.com/scriptverify/ and hit the Verify button. An example screenshot is located below:

Results from Chrome 7:

image

Results from Internet Explorer 8 (With Silverlight Disabled):

image

Tip/Trick #17)

What is it? Use Lambdas whenever you can.

Why do I care? It is my personal opinion that code is easier to read using Lambdas after you get past the syntax.

How do I do it: For example: You may write code like the following:

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    //Check and see if we have a newer .XAP file on the server
    Application.Current.CheckAndDownloadUpdateAsync();
    Application.Current.CheckAndDownloadUpdateCompleted += 
			new CheckAndDownloadUpdateCompletedEventHandler
				(Current_CheckAndDownloadUpdateCompleted);
}

void Current_CheckAndDownloadUpdateCompleted(object sender, 
		CheckAndDownloadUpdateCompletedEventArgs e)
{
    if (e.UpdateAvailable)
    {

        MessageBox.Show(
            "An update has been installed. 
		To see the updates please exit and restart the application");
    }
}

To me, this style forces me to look for the other method to see what the code is actually doing. The style located below is much easier to read in my opinion and does the exact same thing.

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    //Check and see if we have a newer .XAP file on the server
    Application.Current.CheckAndDownloadUpdateAsync();
    Application.Current.CheckAndDownloadUpdateCompleted += (s, e) =>
    {
        if (e.UpdateAvailable)
        {
            MessageBox.Show(
                "An update has been installed. 
		To see the updates please exit and restart the application");
        }
    };
}

Tip/Trick #18)

What is it? Prevent development Web Service references from breaking when Visual Studio auto generates a new port number.

Why do I care? We have all been there, we are developing a Silverlight Application and all of a sudden, our development web services break. We check and find out that the local port number that Visual Studio assigned has changed and now we need up to update all of our service references. We need a way to stop this.

How do I do it: This can actually be prevented with just a few mouse click. Right click on your web solution and goto properties. Click the tab that says, Web. You just need to click the radio button and specify a port number. Now you won’t be bothered with that anymore.

image

Tip/Trick #19)

What is it? You can disable the Close Button a ChildWindow.

Why do I care? I wouldn’t blog about it if I hadn’t seen it. Devs trying to override keystrokes to prevent users from closing a Child Window.

How do I do it: A property exist on the ChildWindow called “HasCloseButton”, you simply change that to false and your close button is gone. You can delete the “Cancel” button and add some logic to the OK button if you want the user to respond before proceeding.

image

image

Tip/Trick #20)

What is it? Cleanup your XAML.

Why do I care? By removing unneeded namespaces, not naming all of your controls and getting rid of designer markup, you can improve code quality and readability.

How do I do it: (This is a 3 in one tip.)

Remove unused Designer markup:

1)

Have you ever wondered what the following code snippet does?

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"

This code is telling the designer to do something special with this page in “Design mode”, specifically the width and the height of the page. When it's running in the browser, it will not use this information and it is actually ignored by the XAML parser. In other words, if you don’t need it, then delete it.

2)

If you are not using a namespace, then remove it. In the code sample below, I am using Resharper which will tell me the ones that I’m not using by the grayed out line below. If you don’t have Resharper, you can look in your XAML and manually remove the unneeded namespaces.

image

3)

Don’t name a control unless you actually need to refer to it in procedural code. If you name a control, you will take a slight performance hit that is totally unnecessary if it's not being called.

<TextBlock Height="23" Text="TextBlock" />

That is the end of the series. I hope that you enjoyed it and please check out Part 1 | Part 2 | Part 3 if you are hungry for more.

alt Subscribe to my feed

<iframe marginwidth="0" marginheight="0" src=""http://ads.geekswithblogs.net/a.aspx?ZoneID=5&Task=Get&PageID=31016&SiteID=1"" frameborder="0" width="1" scrolling="no" height="1" />

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

mbcrump
Software Developer (Senior) Telerik
United States United States
Michael Crump is a Silverlight MVP and MCPD that has been involved with computers in one way or another for as long as he can remember, but started professionally in 2002. After spending years working as a systems administrator/tech support analyst, Michael branched out and started developing internal utilities that automated repetitive tasks and freed up full-time employees. From there, he was offered a job working at McKesson corporation and has been working with some form of .NET and VB/C# since 2003.
 
He has worked at Fortune 500 companies where he gained experience in embedded systems design and software development to systems administration and database programming, and everything in between.
 
His primary focus right now is developing healthcare software solutions using Microsoft .NET technologies. He prefers building infrastructure components, reusable shared libraries and helping companies define, develop and automate process standards and guidelines.
 
You can read his blog at: MichaelCrump.net or follow him on Twitter at @mbcrump.
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 5 PinmentorSandeep Mewara24-Dec-10 20:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 25 Dec 2010
Article Copyright 2010 by mbcrump
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid