DCSIMG
August 2008 - Posts - Alex Golesh's Blog About Silverlight Development

August 2008 - Posts

Silverlight Isolated Storage Maximum Quota

I've been asked couple of times (by clients, eMail and also here in comments) about maximum size for Silverlight Isolated Storage.

From tests I did, seems that maximum quota size is theoretically limited by total of long.MaxValue number of bytes.

   1: // Request more quota space.
   2: if (!store.IncreaseQuotaTo(long.MaxValue))
   3: //if (!store.IncreaseQuotaTo(store.Quota + spaceToAdd))
   4: {
   5:     // The user clicked NO to the
   6:     // host's prompt to approve the quota increase.
   7:     tbResults.Text = "User declined to approve Quota inrease";
   8: }
   9: else
  10: {
  11:     // The user clicked YES to the
  12:     // host's prompt to approve the quota increase.
  13:     tbResults.Text = "Quota inreased";
  14: }

image

image

So, who have 8,589,934,592Gb HDD? :)

 

The sample used to check it is the same sample from this post. Sources here (the only thing was changed is the size of requested quota in bIncreaseAllocation_Click function like in code snippet).

 

Enjoy,

Alex

Silverlight 2 Beta 2 tools refresh for Visual Studio 2008 SP1

As you probably know, SP1 for Visual Studio 2008 and .NET 3.5 is RTM.

If you work on Silverlight 2 projects and want to upgrade you Visual Studio 2008 you should get this update:

Silverlight 2 Beta 2 tools refresh for SP1 RTM

 

The installation order is follows:

First install Visual Studio 2008 SP1 (download here)

Then install Silverlight 2 Beta 2 Refresh (download here)

 

Enjoy,

Alex

Quick Silverlight Tip: Creating/Destroying Silverlight 2 Object dynamically

One of my clients asked me how to create and show (and then destroy) Silverlight application on the fly.

Here is very fast solution, which allows such an object to be created and destroyed.

First, we (still) need to have some DIV which will hold the object. Here is my sample page HTML:

   1: <body>
   2:     <!-- Runtime errors from Silverlight will be displayed here.
   3:     This will contain debugging information and should be removed or hidden when debugging is completed -->
   4:     <div id='errorLocation' style="font-size: small;color: Gray;"></div>
   5:     
   6:     <input id="Button1" type="button" value="Make SL" onclick="MakeSL();" />
   7:     <input id="Button2" type="button" value="Hide SL2" onclick="HideSL('silverlightControlHost');" />
   8:     <div id="silverlightControlHost" style="left:10px;top:10px;height:200px;width:320px">
   9:     </div>
  10: </body>

Now let's see the "MakeSL" and "HideSL" JavaScript functions:

   1: function MakeSL()
   2: {
   3:     //Create Silverlight object as a string
   4:     var objScript = '<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">';
   5:     objScript += '<param name="source" value="ClientBin/TestApp.xap"/>';
   6:     objScript += '<param name="onerror" value="onSilverlightError" />';
   7:     objScript += '<param name="background" value="white" />';
   8:     objScript += '<a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">';
   9:      objScript += '<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>';
  10:     objScript += '</a>';
  11:     objScript += '</object>';
  12:     objScript += '<iframe style="visibility:hidden;height:0;width:0;border:0px"></iframe>';    
  13:     
  14:     //Helper function call -> will add the object to DIV
  15:     writer(objScript, "silverlightControlHost");
  16: }
  17:  
  18: function HideSL(id)
  19: {
  20:     //Remove object's InnerHTML -> in case of DIV with Silverlight object it also ends the Silverlight application
  21:     document.getElementById(id).innerHTML="";                
  22: }
  23:  
  24: function writer(txt, id)
  25: {
  26:     //Get DIV element and put objectString into its InnerHTML
  27:     var element = document.getElementById(id);
  28:     element.innerHTML = txt;
  29: }

That's it... Now let's run the solution:

At the beginning - no Silverlight at page...

image 

After clicking "Make SL" button application's object being created and the application being loaded:

image

Pressing "Hide SL" button (while debugging application) brings us to "Application_Exit" breakpoint and also cleans the object:

image image

 

Mission accomplished - Silverlight application added and fully removed dynamically.

Source for sample here.

 

Enjoy,

Alex