Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

April 2010 - Posts

New Silverlight Blog

UPDATE (5/11/2010)

I am changing my domain for my new Silverlight blog to be:

 http://www.michaelsnow.com

I will be retiring the name silverlightdev.net so expect this link to go dead after some time.

Sorry for an inconvenience.

--Mike


After a long hiatus from Silverlight (due to my team being moved off Silverlight ) I am back to blogging for Silverlight!

When it comes down to technologies, Silverlight is my greatest passion. I spend a lot of my spare time experimenting with building a wide variety of applications using Silverlight.

Going forward, I will be showcasing these applications as well as regular tips and tutorials on my new blog which can be found at:

http://www.silverlightdev.net

Using my own site I will be able to include live demos and sample source code with each tip of the day. I will be cleaning up and migrating a number of tips from here that I find still to be applicable and useful for Silverlight 4 and beyond.

Thanks,
--Mike

Tip of the Day #111 – How to Configure your Silverlight App to run in Elevated Trust Mode

With Silverlight you can run your Out-of-Browser applications in elevated trust mode. This will allow you to relax the normal sandboxed barrier Silverlight restricts applications to. While you still will not have full control of the local machine, the following features are made available to you in elevated trust mode:

  1. Clipboard Access – Retrieve items from the system clipboard without the prompt for permissions to access  the clipboard as seen below:

    image 
  2. HTML Hosting – Display HTML Content in the WebBrowser control.

  3. Removal of Cross Domain Restrictions – Your application can interact with any domain bypassing the normal security check that required the ClientAccessPolicy.xml or CrossDomain.xml files.

  4. File Access – Your application can now directly access files without user initiated interaction that then invokes the OpenFileDialog or SaveFileDialog dialogs. However, you are still limited to user folders such as My Documents, My Videos, My Music, My Pictures and any sub folder. Example code you can execute:

    if
    (App.Current.IsRunningOutOfBrowser && Application.Current.HasElevatedPermissions)
    {
        string picturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
        string path = picturesPath + @"\test.txt";
        StreamReader sr = new StreamReader(path);

        string line = sr.ReadLine();
        while (line != null)
        {
            line = sr.ReadLine();
        }
        sr.Close();
    }

  5. Notification Window – Also know as a “toast” window, this is a small window that pops up in the lower right corner for a specified interval of time before disappearing.

  6. COM Interoperability – Direct access to COM enabled applications installed on the clients machine.

In order to configure your application to run in elevated mode open your project in Visual Studio 2010. Once open, right click on your Silverlight application in the solution explorer and select Properties. Under the Silverlight tab, check “Enable running application out of the browser” and click the “Out-of-Browser settings" button as circled below in the screenshot.

image

Once this dialog is open check the “Require elevated trust when running outside the browser” checkbox as seen circle in the screenshot below.

image

Now, when a user chooses to install your Silverlight application out of browser they will get this rather intimidating security warning dialog before they can proceed. Note that you can replace this dialog with something more friendly if your XAP is digitally signed (this will be covered in the next tip of the day).

image 

Final Notes

On a final note, you will want to make certain your application verifies it’s running in out of browser mode before making calls that are required to be in this mode before being executed. Your application can check to see if it’s running in Out-of-Browser mode through this call:

if (App.Current.IsRunningOutOfBrowser)
{
}

Also, your application can verify it has elevated permissions with this call:

if (Application.Current.HasElevatedPermissions)
{
}

Thank you,
--Mike

Tip of the Day #110 – Using Static Resources in Class Libraries

This blog has been migrated to the new site:

http://www.michaelsnow.com/2010/04/21/tip-of-the-day-1-using-static-resources-in-class-libraries/

Silverlight 4 Tools Released

This morning we released Silverlight 4 Tools for Visual Studio 2010!

The link to download and installs the tools is http://go.microsoft.com/fwlink/?LinkId=177508

The tools will install:

  1. Silverlight 4 RTM Developer Runtime
  2. Silverlight 4 Tools RC for VS 2010
  3. Silverlight 4 SDK RTM
  4. Silverlight 4 Tools RC Package
  5. WCF RIA Services RC

Note that this is the RC release of the Silverlight 4 tools. With these tools you can start developing Silverlight 4 applications using Visual Studio 2010.

If you are not familiar with what’s new in SL 4 check out Tim’s blog here: http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx

If you haven’t already downloaded VS 2010, you can get the free Express version from here: http://www.microsoft.com/web/gallery/install.aspx?appid=VWD2010.

If you are a MSDN subscriber you can get the full version here: http://www.microsoft.com/visualstudio/en-us/download

Thanks and enjoy!

--Mike

Silverlight Tip of the Day #109 – Attach to Process Debugging

This blog has been migrated.
The new link for this tip is at: http://www.michaelsnow.com/2010/04/22/silverlight-tip-of-the-day-2-attach-to-process-debugging/

Posted: Apr 08 2010, 10:54 AM by mike.snow | with 6 comment(s)
Filed under: