tag:blogger.com,1999:blog-68107712024-03-12T17:16:34.960-07:00Even a chimp can write codeIdeas on software and elsewhere by Ashish Shetty: erstwhile chimp and occasional re-inventor of the wheel.Unknownnoreply@blogger.comBlogger254125tag:blogger.com,1999:blog-6810771.post-27104841256149950192012-03-15T11:36:00.000-07:002012-03-15T11:36:06.881-07:00High performance UI without compromisesIn my last post I left a teaser about more information forthcoming on XAML-DX interop. Wait no more. Jesse Bishop on my team has a post on <a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/03/15/combining-xaml-and-directx.aspx">Combining XAML and DirectX</a> over on the Windows 8 app developer blog.<br />
<br />
This feature is especially dear to me. Its one of the handful of things I had in the first deck outlining what the new XAML platform in Windows 8 was going to be. We spent the couple months preceding the release of the Developer Preview working on a brand new graphics stack with independent animation support, and it was only once that was in place that we could expose the niceties of this interop feature set.<br />
<br />
Together with our web interop story, surfaced via the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.aspx">WebView control</a>, the XAML-DX interop feature set represents our beliefs that app developers shouldn't have to pick between reuse and new code, nor between high performance and high productivity. <a href="http://social.msdn.microsoft.com/Forums/en-US/category/windowsapps">Your feedback</a> is appreciated.Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6810771.post-60688967773783789712012-03-12T15:06:00.000-07:002012-03-12T15:08:01.594-07:00Maps and Ads controls for Windows 8 Metro style appsI wanted to highlight a couple controls that developers authoring Metro style apps will find useful. The Bing team recently announced a beta of their <a href="http://go.microsoft.com/fwlink/?LinkId=242709">Bing Maps SDK</a> with controls allowing you to integrate maps into your apps. The control targeted at XAML apps is especially neat. It relies on new XAML-DX interop features we added after the Developer Preview, and available in the Consumer Preview of Windows 8. More on that soon. Meanwhile I hope you try out the Maps app in the Consumer Preview to get a good feel for how great rendering performance can be achieved without compromises. The <a href="http://www.bingmapsportal.com/">Bing Maps Portal</a> has docs and other assets for your development.<br />
<br />
At about the same time, the Microsoft Advertising team <a href="http://community.microsoftadvertising.com/blogs/advertising/archive/2012/03/06/developers-microsoft-advertising-sdk-windows-metro-apps.aspx">announced a beta of their Ads SDK</a> for Windows 8 allowing developers to integrate ads into their apps.<br />
<br />
Each is a custom control authored in a way as to provide a familiar programming model to HTML/JavaScript, XAML/C# and XAML/C++ developers alike. This is also a testament to the <a href="http://timheuer.com/blog/archive/2012/03/07/creating-custom-controls-for-metro-style-apps.aspx">custom controls</a> story in the XAML platform in Windows 8 and I hope to see others - controls vendors as well as folks with interesting web services - package up their functionality for use by the surge of Windows 8 apps to come.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6810771.post-35339178925309651762012-02-29T08:27:00.004-08:002012-02-29T08:45:09.936-08:00Windows 8 Consumer PreviewToday the Windows team announced the release of the <a href="http://preview.windows.com/">Windows 8 Consumer Preview</a>, coming on the heels of the <a href="http://dev.windows.com">Developer Preview</a> we'd released last year. While the next best thing is still a work in progress we hope you will try it out and <a href="http://go.microsoft.com/fwlink/p/?LinkId=238545">tell us</a> what you think.<br /><br />There's also a <a href="http://blogs.msdn.com/b/windowsappdev/">new Windows developer blog</a> where we can continue our conversation with the developer community.<br /><br />Thanks to developers worldwide for your interest in Windows 8 thus far, for <a href="http://msdn.microsoft.com/en-us/windows/apps/br229515/">your feedback </a>and the great apps you are building or planning - and for being true north for the XAML developer platform team and me.<br /><br /><em>PS: Yes I'm alive. Now you know what I've been up to.</em>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-6810771.post-15561031978374228822010-04-15T14:41:00.000-07:002010-04-15T15:22:26.610-07:00Of Crashing and Sometimes BurningI don't feel we've narrated the story about error and exception handling in Silverlight very well. We started out in v1.0 with a relatively sucky error reporting and diagnostics story and only did real work in building a robust internal infrastructure and adding diagnostics support incrementally, starting with Silverlight 2. We've since made big strides.<br /><br />Our core tenet is to always provide a robust and reliable operating experience for apps.<br /><br /><h4>What conditions can cause crashes?</h4>Crashes are rare occurences. Ideally we'd avoid them altogether. They are symptoms of one of the following conditions:<br /><br /><ol><li>A bug in the platform</li><li>A security mitigation being acted out</li><li>The app doing an illegal reentrant call</li></ol><p><strong>Crashes due to platform bugs</strong><br />These are rare because few bugs of that severity ever get past our quality gates. This remedy is used within Silverlight only in situations where there's a reasonable chance the platform is in uncertain state and going ahead might be fraught with problems. Within this category, there are two variants: shutting down the app and then the runtime; and tearing down the host process. </p><p>Of the two variants, the former is the more common approach. It is typical for Silverlight to notify the app via Application.UnhandledException, and most times followed by raising the OnError DOM event for the OBJECT tag prior to shutdown. If you don't see either of these happening, then that might also indicate a bug, and you should report it. </p><p>In some situations Silverlight may not consider it tenable to continue processing. Instead it takes recourse to a failfast - aka a forceful teardown. Examples include when the internal state machine appears to be corrupt or required data is missing (an ExecutionEngineException thrown but not necessarily).</p><p>If you think you've found a platform bug that is causing crashes, we'd love to get our hands on a simplified repro app with sources. If the bug does not reproduce reliably, we'd appreciate crash dumps. </p><p>We will fix most of these issues as and when they're reported.</p><p><strong>Crashes due to an in-built security mitigation</strong><br />When Silverlight detects an Access Violation (aka segfault) or a Stack Overflow, or a Buffer Overflow, the runtime's built-in failfast routines kick in. These are deliberately designed to disallow app code to catch/suppress/rethrow these exceptions, and instead prevent any exploit from taking effect. Doing that would be folly... therein lie known attack vectors. Even in the most benign situations Silverlight assumes past performance is an indicator of future performance (<em>no, we wouldn't be good investors with that mindset!</em>) and finds its extreme action justifiable. </p><p>We will not "fix" issues in this category.</p><p><strong>Crashes due to reentrancy</strong><br />Silverlight does not deal well with reentrant behavior. Simply put, if Silverlight calls app code in a synchronous callout, it expects the call to be blocking, and it does not expect to be called back via that or another avenue until the blocking call exits. But when it finds itself in this situation, Silverlight will teardown with extreme prejudice, bringing down app, runtime and host (browser) together with a Null AccessViolation. A Null AV is different from a regular AV.</p><p>Here's how to tell if this is happening to you. The simple way is to look for "Null AccessViolation" in your dump. A more contrived way requires symbols and involves looking at the callstack:</p><pre>KernelBase.dll!DebugBreak() Line 81 C<br />npctrl.dll!CWindowsServices::DebugBreak() Line 4270 + 0x8 bytes C++<br />npctrl.dll!DisplayDebugDialog(unsigned int uClass=1, unsigned short * pFileName=0x5ef4ef78, int iLine=64, int iValue=0, unsigned short * pTestString=0x5ef36dec, unsigned short * pMessage=0x037d9a0c) Line 926 C++<br />npctrl.dll!XcpVTrace(unsigned int uClass=1, unsigned short * pFileName=0x5ef4ef78, int iLine=64, int iValue=0, unsigned short * pTestString=0x5ef36dec, unsigned short * pMessageString=0x5ef31e78, void * pVArgs=0x037d9c00) Line 1036 C++<br />npctrl.dll!CWindowsServices::XcpTrace(unsigned int uClass=1, unsigned short * pFilename=0x5ef4ef78, int iLine=64, int iValue=0, unsigned short * pTestString=0x5ef36dec, unsigned short * pMessageString=0x5ef31e78, ...) Line 7258 C++<br />npctrl.dll!<span style="color:#ff0000;">CReentrancyGuard::CheckReentrancy</span>(int bNullAvOnReentrancy=1) Line 64 + 0x36 bytes C++<br />npctrl.dll!CXcpDispatcher::OnReentrancyProtectedWindowMessage(HWND__ * hwnd=0x004b039a, <span style="color:#ff0000;">unsigned int msg=1026</span>, unsigned int wParam=0, long lParam=0) Line 900 + 0xa bytes C++<br />npctrl.dll!CXcpDispatcher::WindowProc(HWND__ * hwnd=0x004b039a, unsigned int msg=1026, unsigned int wParam=0, long lParam=0) Line 807 + 0x18 bytes C++<br />user32.dll!_InternalCallWinProc@20() Line 106 Asm<br />user32.dll!UserCallWinProcCheckWow(_ACTIVATION_CONTEXT * pActCtx=0x00000000, long (HWND__ *, unsigned int, unsigned int, long)* pfn=0x5f10bc90, HWND__ * hwnd=0x004b039a, _WM_VALUE msg=1026, unsigned int wParam=0, long lParam=0, void * pww=0x00e267f8, int fEnableLiteHooks=1) Line 163 + 0x12 bytes C<br />user32.dll!DispatchMessageWorker(tagMSG * pmsg=0x5f10bc90, int fAnsi=0) Line 2591 + 0x1e bytes C<br />user32.dll!DispatchMessageW(const tagMSG * lpMsg=0x037d9dec) Line 999 C<br />user32.dll!DialogBox2(HWND__ * hwnd=0x002902ac, HWND__ * hwndOwner=0x000b0924, int fDisabled=0, int fOwnerIsActiveWindow=0) Line 1150 C<br />user32.dll!InternalDialogBox(void * hModule=0x760b0000, DLGTEMPLATE * lpdt=0x04923388, HWND__ * hwndOwner=0x000708fe, int (HWND__ *, unsigned int, unsigned int, long)* pfnDialog=0x7611eec8, long lParam=58564704, unsigned int fSCDLGFlags=0) Line 1314 + 0x9 bytes C<br />user32.dll!SoftModalMessageBox(_MSGBOXDATA * lpmb=0x00000030) Line 1237 + 0x18 bytes C<br />user32.dll!MessageBoxWorker(_MSGBOXDATA * pMsgBoxParams=0x037da060) Line 791 C<br />user32.dll!<span style="color:#ff0000;">MessageBoxIndirectW</span>(const tagMSGBOXPARAMSW * lpmbp=0x037da0d4) Line 528 + 0xe bytes C<br />ieframe.dll!6132ecd5() </pre>The presence of <code>CReentrancyGuard::CheckReentrancy</code> indicates the reentrancy guard; message 1026 indicates WM_INTERNAL_TICK the veritable sign of the <strike>apocalypse</strike> reentrancy; and the presence of a (non-Silverlight, in this case from NTUser) MessageBox at the bottom indicates an actor that pumps messages including Silverlight messages. Note that Silverlight's own MessageBox will not cause this reentrancy - it and the reentrancy guard were specifically designed to play well with each other. So I recommend using that any place you'd consider using an alert.<br /><br /><p>Now consider that SizeChanged and LayoutUpdated events are raised synchronously as part of a layout pass. (I've previously expressed <a href="http://nerddawg.blogspot.com/2008/07/death-taxes-and-latency.html">my firm preference for all things async</a> -- I'd have loved for these events to be async but lost that argument since it'd have broken WPF compat and eliminated a couple scenarios. But I digress.) Now if you were to use the DOM Bridge within a SizeChanged event handler to, say, do an alert(), that'd align all the stars. The alert would pump messages; Silverlight would be in a blocking call, not expecting any messages in its internal queue; its little "reentrancy guard" would see this as reentrant behavior, and initiate adverse action terminating with a Null AV.</p><p></p><p>Silverlight's behavior in this situation was intended to be moral equivalent of a shock collar. We wanted app authors to detect these situations at development time and fix their code, so it never shipped with reentrant behavior. </p><p>This condition is the most common cause for crashes in Silverlight, and is indicative of programming error in the app.</p><p>We're constantly evaluating whether this sort of positive reinforcement through <a href="http://en.wikipedia.org/wiki/Operant_conditioning">operant conditioning</a> actually works. If you have anecdotes or feedback, please drop a line. Bear in mind that we have done a poor job at advertising this behavior, and I do sincerely apologize. So the fact that it took you a good while longer than average to debug such an issue is unfortunate but explained away by that.</p><p><strong>Where to look for crash dumps?</strong><br />While developing apps on Windows, with Windows Error Reporting (Watson) you should see the path in the UI shown upon a crash. Alternately look under %Temp% for dirs with "WER" prefix, and look for a .mdmp file prefixed by process name. If this is an out of browser app, you should see "sllauncher.exe.mdmp" instead of one for the browser's executable.</p><p></p><p><h4>Further reading</h4>With the context from this post, I hope you will see the MSDN doc on <a href="http://msdn.microsoft.com/en-us/library/cc189070(VS.95).aspx">Silverlight Error Handling</a> in new light. Some of that content originated from my original spec on the topic written circa Silverlight 2. It will help you understand control flow. In addition, this topic page will help you understand <a href="http://msdn.microsoft.com/en-us/library/2w8f0bss(VS.95).aspx">how best to handle exceptions in your own Silverlight app code</a>. <p></p><br /><br /><h4>A word on diagnostics</h4>If we could rewrite the past and change something, we'd have tweaked our initial conditions to one that enforced error reporting best practices in our internal development of the runtime. This would have eliminated having to perform triage and surgery on a rapidly evolving runtime as we added better diagnostics. There are still too many E_FAILs in our code that bubble up and result in the totally unhelpful "Unknown error" and the wildly melodramatic "Catastrophic error". There's a bit of dark humor in the backstory, but that's for another time.<br /><br />Our work is not done though. We continue to seek feedback from app authors and fix our oversights. Keeping Silverlight easy to develop against is a giant priority for our team. Making sure you have great diagnostics and get past issues fast is one way we can make that happen.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6810771.post-64814044434995982412010-04-15T12:28:00.000-07:002010-04-15T12:46:44.737-07:00Four scores!Silverlight 4 is now live! Here's <a href="http://www.silverlight.net/getstarted/silverlight-4/#whatsnew">what's new</a>.<br /><ul><li>End users can get it here: <a href="http://www.microsoft.com/GetSilverlight">microsoft.com/GetSilverlight</a><br /></li><li>App authors can get the runtime and tools here: <a href="http://www.silverlight.net/getstarted/">silverlight.net/GetStarted</a><br /></li><li>Developer docs for Silverlight are <a href="http://msdn.microsoft.com/en-us/library/cc838158(v=vs.95).aspx">on MSDN</a></li></ul><p>The team is taking a much-deserved couple days off to recharge. Besides, the sun's out in Seattle this week - after what seems like decades.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6810771.post-2864908342147946802010-04-15T12:24:00.000-07:002010-04-15T12:28:15.581-07:00Can you access a loose XAML file from LoadComponent?<p>The answer is no. The job of <a href="http://msdn.microsoft.com/library/ms596995(VS.95).aspx">Application.LoadComponent</a> in Silverlight is to “merge” a specified XAML file with a specified object. </p><code>public void Application.LoadComponent(object, Uri);</code> <p>In doing so, it does a series of validations:</p><ul><li>checks that neither parameter is null </li><li>checks whether the specified XAML URI is absolute or relative. Absolute URIs are not allowed. </li><li>checks whether the specified XAML is embedded within an assembly. If not, LoadComponent fails. </li><li>checks whether the root element declared in the specified XAML is actually the same type as that of the specified object. If not, LoadComponent fails. </li></ul><p>and only then attempts to merge the two in a custom parsing step.</p><h4>Well, why not?</h4><p>The last bullet point above is consequential in why we don’t allow loose XAML. LoadComponent thinks of an assembly as a logical boundary. In the presence of XAML with contents like this:</p><code><UserControl x:Class=”Foo”> …</code> <p>the only unambiguous way for Silverlight to identify and locate “Foo” is if it knew the DLL where that type was defined. Iterating through all DLLs loaded in the AppDomain isn’t an optimal solution at all. This is why it insists that the XAML be embedded within a DLL. Then it knows the un-qualified type is defined within that DLL. In practice, the URI specified on the LoadComponent call ends up being something like: </p><code>/SomeAssemblyName;component/Page.xaml</code> <p>which has metadata on the provenance of said XAML i.e. that it came from an assembly with short name “SomeAssemblyName”. Silverlight can now happily match it against the type backing the other specified parameter – the object.</p><h4>How does one work around this?</h4><p>A workaround exists, but it has some limitations. You can use XamlReader.Load() to have Silverlight create an <a href="http://msdn.microsoft.com/en-us/library/cc189034(VS.95).aspx">object tree</a> from your specified markup. The caveat being that said XAML cannot have <a href="http://msdn.microsoft.com/en-us/library/cc221357(VS.95).aspx">code-behind associations</a> i.e. a backing type as root element, or event handler declarations. This approach is ideal if you’re dealing with sprites that are injected into the app, with other plumbing hooked up programmatically.</p><p> </p><p><span style="font-size:78%;">Aside: This is part of a <em>recycling bits</em> series I've been considering for a while. I frequently find myself answering the same questions over email or other forums, and figure I'd give some of those FAQs airtime on this blog, so as to multiply any benefits the information might have.</span></p>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6810771.post-51120596041589135832010-03-18T16:17:00.000-07:002010-03-18T16:44:25.777-07:00Stepping outside the browser with Silverlight 4Thanks to all those who attended the talk "CL10 - Stepping outside the browser with Silverlight 4" at the Mix 2010 conference or caught it via the <a href="http://live.visitmix.com/MIX10/Sessions/CL10">recorded session online</a>. I talked about the evolution of Silverlight into a general purpose development platform, far away from its origins as a browser plugin. I walked through features that light up outside the browser through our deliberate nested doll design approach - both in Silverlight 3 and continuing into Silverlight 4 now. I also talked about trusted apps and emphasized how important getting the right user experience and removing friction from app deployment was to us in the Silverlight team.<br /><br />Here is the <a href="http://cid-404c2ff7814e399f.skydrive.live.com/self.aspx/Public/Silverlight%20beyond%20the%20browser/Mix2010%5E_CL10%5E_SteppingOutsideTheBrowserWithSilverlight4.pptx">slide deck from the talk</a>. Source code for the basic sandboxed app is archived <a href="http://cid-404c2ff7814e399f.skydrive.live.com/self.aspx/Public/Silverlight%20beyond%20the%20browser/SandboxedApp.zip">here</a>; and code for the trusted app can be found <a href="http://cid-404c2ff7814e399f.skydrive.live.com/self.aspx/Public/Silverlight%20beyond%20the%20browser/ImageShop.zip">here</a>. Hope you find it valuable.<br /><br />The Q&A session at the end was very useful. I appreciate all the interest in this space and was happy to learn of the apps people were building. We could only get here "with a little help from our friends" in the ecosystem. We can continue that conversation on this blog, or you can send me email (ashsh).<br /><br /><br /><span style="font-size:78%;">Update: as a postscript, the slide deck I linked to here looks different from the one I used in the talk. Due to "technical difficulties" the podium machine had an older copy of the deck from one of my previous uploads, and I only found out once I was into the talk (silly me for not checking). So if I looked like I crapped a brick at the beginning, now you know why. Live and learn.</span>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-6810771.post-74271781015034713422009-07-25T15:45:00.001-07:002009-07-25T15:51:34.808-07:00Silverlight out-of-browser apps: Remove<p>Removing a Silverlight out-of-browser app is as easy as <a title="Installing a Silverlight offline and out-of-browser app" href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-install.html">installing</a> it was previously. From within the app, just right-click and choose <em>“Remove this application…”</em>. </p> <a href="http://1.bp.blogspot.com/_vO3QC5qlK78/SmuLaNCX-UI/AAAAAAAAAFs/x-TPe6N6RXk/s1600-h/SL+out-of-browser+Remove+context+menu+item.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 242px; height: 70px;" src="http://1.bp.blogspot.com/_vO3QC5qlK78/SmuLaNCX-UI/AAAAAAAAAFs/x-TPe6N6RXk/s320/SL+out-of-browser+Remove+context+menu+item.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5362533063607187778" /></a><p>Just so you don’t wipe away apps by accident, Silverlight will ask you to confirm, and when you do, the app is uninstalled and its binaries are scavenged from the offline application cache. </p><a href="http://4.bp.blogspot.com/_vO3QC5qlK78/SmuLaa0twJI/AAAAAAAAAF0/gfSoAw8vlLU/s1600-h/SL+out-of-browser+Remove+confirmation.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 124px;" src="http://4.bp.blogspot.com/_vO3QC5qlK78/SmuLaa0twJI/AAAAAAAAAF0/gfSoAw8vlLU/s320/SL+out-of-browser+Remove+confirmation.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5362533067307991186" /></a><p>Data persisted by the app into <a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-local.html">local data store</a> (Isolated Storage) is not removed. It is still consumable by the in-browser version of the app.</p> <p>On Mac OS X, dragging the app bundle into the Trash can is another way to remove the app. </p> <p>In line with our guiding principles which involve keeping the consumer end user firmly in control, keeping it simple and staying out of the way, the Remove experience does not allow the app to programmatically delay, defer or prevent its own uninstall.</p> <p>Previous posts in this series:</p> <ul> <li><a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">Introducing Offline and Out of Browser support in Silverlight</a></li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-support-what.html">The kinds of apps you can build</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-install.html">Install</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-launch.html">Launch</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-network.html">Network Awareness</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-local.html">Local Data Store</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/07/silverlight-out-of-browser-apps-how.html">Updates</a></li> </ul>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-6810771.post-56490201318111514782009-07-10T19:58:00.001-07:002009-07-10T20:14:53.243-07:00Silverlight out-of-browser apps: How Updates Work<p>Silverlight makes updating your <a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">out-of-browser XAP</a> a breeze. It does the heavy lifting for you, asking that you merely invoke the update logic from within your app at a time or frequency of your choosing, and respond to events raised by Silverlight. </p><p>If an updated XAP has been published to your web server, Silverlight will download and induct it to the offline application cache. The next time your app is activated, Silverlight will ensure the updated bits are activated and the old bits are scavenged.</p><h4>What the app author needs to do</h4><p>Employ the async-pattern APIs exposed for updates in your out-of-browser apps. The trigger method is the <code>Application.CheckAndDownloadUpdateAsync()</code> method. Hook up an event handler for the <code>CheckAndDownloadUpdateCompleted</code> event. See, there’s not much to it! No messing with version numbers or the like.</p><h4>Gotchas?</h4><p>Well the only thing to watch out for is the situation when a new version of Silverlight comes out (say v4) and your app is built against it, but the consumer is running an older runtime (say, v3) and an appropriate older version of your app. In this situation, the app update cannot be applied because it requires a runtime update first. Silverlight notifies your app of this situation by setting the event arg’s <code>Error</code> property value to <code>System.PlatformNotSupportedException</code>. </p><p>All in all, here’s the code you’re going to write:</p><form id="aspnetForm" method="post" name="aspnetForm" action="http://msdn.microsoft.com/system.windows.application.checkanddownloadupdateasync(VS.95).aspx"><div id="contents"><div id="ctl00_LibFrame" class="resizableArea"><div id="ctl00_raRight" class="rightSection"><div class="RightPanel"><div class="ContentArea"><div class="topic"><div id="mainSection"><div id="mainBody"><div id="ctl00_MTContentSelector1_mainContentContainer_cpe46165" class="MTPS_CollapsibleRegion"><div style="DISPLAY: block" id="ctl00_MTContentSelector1_mainContentContainer_cpe46165_c" class="MTPS_CollapsibleSection"><div id="snippetGroup"><div id="ctl00_MTContentSelector1_mainContentContainer_ctl29_CSharp" class="libCScode"><div dir="ltr"><pre style="WORD-WRAP: break-word; WORD-BREAK: break-all" id="ctl00_MTContentSelector1_mainContentContainer_ctl29CSharp" class="libCScode" space="preserve"><span style="color:blue;">private</span> <span style="color:blue;">void</span> SomeMethod()<br />{<br /> Application.Current.CheckAndDownloadUpdateAsync();<br />}<br /><br /><span style="color:blue;">private</span> <span style="color:blue;">void</span> App_CheckAndDownloadUpdateCompleted(object sender,<br /><br /> CheckAndDownloadUpdateCompletedEventArgs e)<br />{<br /> <span style="color:blue;">if</span> (e.UpdateAvailable)<br /> {<br /> MessageBox.Show(<span style="color:maroon;"><span style="color:maroon;">"An update has been downloaded. "</span></span> +<br /> <span style="color:maroon;"><span style="color:maroon;">"Restart the application to run the new version."</span></span>);<br /> }<br /> <span style="color:blue;">else</span> <span style="color:blue;">if</span> (e.Error != <span style="color:blue;">null</span> &&<br /> e.Error is PlatformNotSupportedException)<br /> {<br /> MessageBox.Show(<span style="color:maroon;"><span style="color:maroon;">"An application update is available, "</span></span> +<br /> <span style="color:maroon;"><span style="color:maroon;">"but it requires a new version of Silverlight. "</span></span> +<br /> <span style="color:maroon;"><span style="color:maroon;">"Visit the application home page to upgrade."</span></span>);<br /> }<br /> <span style="color:blue;">else</span><br /> {<br /> MessageBox.Show(<span style="color:maroon;"><span style="color:maroon;">"There is no update available."</span></span>);<br /> }<br />}</pre><br /><br /></div></div></div></div></div></div></div></div></div></div></div></div></div></form><h4>What the app publisher needs to do</h4><p>If you handle application deployments or administer web servers, all you need to do is xcopy the new XAP (plus any external content files it needs) in place of the old XAP. Silverlight will take it from there. </p><p></p> <p> </p><p>In the end, a word to the wise... Make sure you clearly articulate your app's update policy to your end users. Whether you auto-update, or require user-initiation; whether you update upon every app launch or at another discrete frequency; let your app's consumer audience know. Ideally you'd grant them the ability to override your defaults. This is the right thing to do. The user must always be in control.<br /></p><p> </p><p>Previous posts in this series:</p><ul><br /><li><a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">Introducing Offline and Out of Browser support in Silverlight</a></li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-support-what.html">Silverlight out-of-browser support: What kind of apps can you build?</a> </li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-install.html">Silverlight out-of-browser apps: The Install</a> </li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-launch.html">Silverlight out-of-browser apps: Launch</a> </li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-network.html">Silverlight out-of-browser apps: Network Awareness</a> </li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-local.html">Silverlight out-of-browser apps: Local Data Store</a> </li></ul>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6810771.post-87078526525349406802009-07-10T09:58:00.000-07:002009-07-10T19:27:48.100-07:00Three Years and Three VersionsSilverlight 3 just shipped! 3 is so much bigger than 2; and here's <a href="http://silverlight.net/getstarted/silverlight3/default.aspx">what's new</a>. See <a href="http://weblogs.asp.net/scottgu/archive/2009/07/10/silverlight-3-released.aspx">Scott's post </a>announcing the release to web (RTW) and outlining the major features.<br /><br /><a href="http://www.microsoft.com/silverlight">Microsoft.com/silverlight</a> gets a facelift. Goodbye dusk (theme), hello dawn. Be sure to check out the <a href="http://www.microsoft.com/silverlight/overview/default.aspx">overview of Silverlight 3 there</a>.<br /><br />Thanks to all of you for your persistent feedback and support in making this such a powerhouse of a release. Keep that feedback coming - we're already working on 4.<br /><br />More soon...Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6810771.post-77473608220116823532009-05-09T16:32:00.000-07:002009-05-09T16:49:47.482-07:00User-initiated operations in SilverlightUser-initiated operations in Silverlight:<br /><ol><li>must be initiated by the user via an input device like keyboard, mouse or accessibility client...</li><li>...within Silverlight</li><li>have an in-built timeout</li><li>have atomicity of transaction</li><li>cannot be marshalled across the specific Silverlight plugin's boundaries</li></ol><p>#1 is obvious. </p><p>#2 isn't. Silverlight will not honor user-initiated operations that start from an HTML element, have a JavaScript handler which calls into a Silverlight scriptable API or other such endpoint.</p><p>#3, the in-built timeout in a user-initiated operation exists to eliminate long running, blocking, iterative, recursive tasks within one user-initiated method call. The timeout value is sort of a magic number, chosen to be small enough to no be a pain point for most developers and their scenarios, and large enough not to compromise on its goals.</p><p>#4 indicates that you cannot combine two operations in Silverlight which both require user initation into one transaction. </p><p>#5 means that the user-initiated "bit" doesn't traverse the Silverlight plugin boundaries, via IPC calls such as local messaging or even intra-process calls via DOM bridge or Scriptable object features.</p><p>These may look like quirks but are actually "features" that exist in Silverlight as secure defaults and to provide consistency of behavior across its supported browser and platform matrix. It is important for every Silverlight designer and developer to understand these nuances.</p>Unknownnoreply@blogger.com6tag:blogger.com,1999:blog-6810771.post-30605593437218081092009-04-27T19:03:00.000-07:002009-04-27T19:03:26.504-07:00Silverlight out-of-browser apps: Local Data Store<p>Silverlight applications – whether in-browser or out-of-browser, and whether running online or offline - can persist data into a local data store referred to as “<a href="http://msdn.microsoft.com/en-us/library/bdts8hk0(VS.95).aspx">Isolated Storage</a>”. With the new offline/out-of-browser support in Silverlight 3, the platform further ensures that an app has access to the <em>same</em> Isolated Storage data regardless of whether it was activated in-browser or locally. This way, apps can share data between the in-browser and out of browser versions. As I’d mentioned in a previous post, Silverlight will enforce the provenance URI of the XAP in either case, ensuring that when each queries for its local store, it gets the very same artifact.</p> <h4>What can you do with this power?</h4> <p>Scenario #0: Local playback sure beats network playback.</p> <p>Scenario #1: Assuming you have consumer use cases that involve using your in-browser and out-of-browser apps interchangeably, you now have a way to share data between them. </p> <p>Scenario #2: If you need to share data between your in-browser app and your newly minted out-of-browser app immediately upon install (detach), you can use this local store as your custom “cookie store”. </p> <p>Scenario #3: If your out-of-browser app detects no network connection, it can still take user input but persist that into local store, to later playback when connectivity is regained.  </p> <h4>Internals</h4> <p>Silverlight’s Isolated Storage feature provides a virtual file system in which apps can create and store both files and directories with arbitrary data. </p> <p>Apps are abstracted from the lower level file I/O functionality; they do not (need to) know where the files are stored or what sort of internal formats and directory hierarchies are in place. While apps can use file paths and dot-out syntax, these paths cannot escape the bounds of the virtual file system. This sort of virtualization provides isolation of app data, preventing other apps from inadvertently reading from or writing to your app’s store. Hence the term “Isolated” in the name. Apps and app authors do need to recognize that data stored in this persistence store is per-user and per-domain.</p> <p>The Isolated Storage feature in Silverlight persists app data within a directory in the user profile (<code>\%AppData%\LocalLow\Microsoft\Silverlight\is</code> on Windows Vista and up and <code>/Users/<user>/Library/Application Support/Microsoft/Silverlight/is</code> on Mac OS X). The AppData folder is a hidden folder. This has the beneficial side effect of hiding your data from from OS search utilities (Windows desktop search and Spotlight) as well as the casual user. This should not be seen as a security boundary – only as a perpetuating the isolation of data.</p> <h4>Quotas</h4> <p>The space allocated for local data storage in a Silverlight app is bounded by a default quota assigned to that app’s domain of origin. At install (detach) time out-of-browser Silverlight apps will have 25MB space available within the Isolated Storage by default. Contrast this to the default quota of 1MB enjoyed by conventional in-browser Silverlight apps.</p> <p>Needless to say, more space is available to the app upon user consent when the app invokes the System.IO.IsolatedStorage.IsolatedStorageFile.IncreaseQuotaTo() method. That method invocation itself needs to be in response to a user-initiated action such as mouse click or key press.</p> <p>When your out-of-browser app is uninstalled, Silverlight does not reclaim your special quota or erase data persisted there. </p> <h4>Encryption</h4> <p>Although the isolated storage maintains data in an obscure location, it should not be confused with secure or encrypted data. However apps can easily <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged(VS.95).aspx">encrypt and decrypt isolated storage files</a>; they may also <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacsha256(VS.95).aspx">sign and validate the signature of an isolated storage file using the SHA256 hash function</a>.</p> <h4>Gotchas</h4> <p>When saving to a virtual file system, one needs to be aware of inherent limits on file path size. This is imposed on you because the Isolated Storage’s root dir itself occupies several characters in the path (151 on Vista/Win7, 183 on XP/2K, 160 on OS X) effectively leaving you only the remainder (109, 77 and 100) respectively for your own file and directory names before Silverlight’s limit of 260 chars for a file path is hit.</p> <h4>Saving files outside of Isolated Storage</h4> <p>Silverlight 3 allows for saving files outside of isolated storage. Saving to any location on the client-side file system requires user initiation and the use of the <a href="http://msdn.microsoft.com/library/system.windows.controls.savefiledialog(VS.96).aspx">SaveFileDialog control</a> - a new “safe” control which allows saving one file at a time via a stream with your app code not having access to the file system or structure. Saving data to the server via an HTTP postback is another option.</p> <p>----</p> <p>This was #6 in my ongoing series of posts on Silverlight’s new offline and out of browser support. Hope it is helping you gear up. </p> <p>Previous posts in this series:</p> <ul> <li><a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">Introducing Offline and Out of Browser support in Silverlight</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-support-what.html">Silverlight out-of-browser support: What kind of apps can you build?</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-install.html">Silverlight out-of-browser apps: The Install</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-launch.html">Silverlight out-of-browser apps: Launch</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-network.html">Silverlight out-of-browser apps: Network Awareness</a>  </li> </ul> <p>Related links:</p> <ul> <li><a href="http://msdn.microsoft.com/library/bdts8hk0(VS.95).aspx">Isolated Storage documentation</a> </li> <li><a href="http://msdn.microsoft.com/library/system.io.isolatedstorage(VS.95).aspx">Isolated Storage API reference</a> </li> <li><a href="http://msdn.microsoft.com/en-us/magazine/dd458794.aspx">MSDN magazine article : Isolated Storage in Silverlight 2</a>  </li> </ul>Unknownnoreply@blogger.com6tag:blogger.com,1999:blog-6810771.post-66011740525552916192009-04-22T16:29:00.001-07:002009-04-22T16:36:10.439-07:00Silverlight out-of-browser apps: Network Awareness<p>There will be times when your Silverlight app is run but the end user does not have a network connection. A key attribute of making a functional offline Silverlight app is building in network awareness. In this post, we’ll look at how easy Silverlight 3 makes this for you.</p> <h4>The API</h4> <p>Silverlight provides current network status via the NetworkInterface.GetIsNetworkAvailable() method. Apps can be notified of changes in network availability via the NetworkChange.NetworkAddressChanged event. The NetworkInterface and NetworkChange types are both declared in the System.Net.NetworkInformation namespace.</p> <p>Here’s sample usage of the network detection APIs:</p> <div style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: #fdffe5; margin-left: 0.05in; border-top: windowtext 1pt solid; margin-right: 0.05in; border-right: windowtext 1pt solid; padding-top: 1pt; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt"> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code">...</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">    </span><span style="color: #424456; mso-themecolor: text2">NetworkChange</span>.NetworkAddressChanged +=  <br /><span style="color: blue">                      new</span> <span style="color: #424456; mso-themecolor: text2">EventHandler</span> (OnNetworkChange);</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code">}</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="color: blue"></span></p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="color: blue"> <br />void</span> OnNetworkChange (<span style="color: blue">object</span> sender,<span style="color: #424456; mso-themecolor: text2"> EventArgs</span> e) </p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code">{<span style="color: blue"> </span> <p></p> </p> <p></p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="color: blue"><span style="mso-spacerun: yes">    </span>if</span> (<span style="color: #424456; mso-themecolor: text2">NetworkInterface</span>.GetIsNetworkAvailable())</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">    </span>{</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-tab-count: 1">     </span><span style="mso-spacerun: yes">   </span>nwIndicatorEllipse.Fill = <br />                              new <span style="color: #424456; mso-themecolor: text2">SolidColorBrush</span>(<span style="color: #424456; mso-themecolor: text2">Colors</span>.Green);</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">        </span><span style="color: #00b050">// and do something</span></p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">    </span>} </p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">    </span><span style="color: blue">else</span> </p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">    </span>{</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-tab-count: 1">     </span><span style="mso-spacerun: yes">   </span>nwIndicatorEllipse.Fill = <br />                              new <span style="color: #424456; mso-themecolor: text2">SolidColorBrush</span>(<span style="color: #424456; mso-themecolor: text2">Colors</span>.Red);</p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">        </span><span style="color: #00b050">// and do something else</span></p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code"><span style="mso-spacerun: yes">    </span>} </p> <p style="margin: 0in 0in 0pt; background: #fdffe5" class="Code">} </p> <p></p> </div> <h4>What This Feature Is</h4> <p>The NetworkAddressChanged event – as the name suggests - advertises a change in IP address (availability). It is to be used in concert with the NetworkInformation.GetIsNetworkAvailable() to identify whether the recent change resulted in the system obtaining an IP address or losing one. The IP address is seen as a good primordial proxy for availability of network connection or lack thereof.</p> <p>This feature is an answer to the question <em>“Is this is a good time to make an outbound network request?”</em>. Silverlight plays an enabling role in detecting offline status, telling you whether it’s worth your while to make an outbound call, or alternately to cache and persist data locally until network connectivity is regained.</p> <h4>What this Feature Isn’t</h4> <p>This feature is not an answer to the question <em>“Is my site (or web service) up and running at this moment?”</em>. The way I see it, Silverlight doesn’t play an enabling role in that situation – that is something your app can achieve with 10 lines of code. And such a service indicator is better off taking the actual URI and returning an actual response, rather than being a glorified HTTP HEAD wrapper.</p> <h4>Gotchas</h4> <p>Say you have 2 adapters – a wireless and wireline Ethernet – both of which are connected. If your wireless connection drops, the NetworkAddressChanged event is raised but in the handler when you query NetworkInformation.GetIsNetworkAvailable(), you still get true because your wireline Ethernet connection is still valid. When that goes down as well, the event is raised yet again and the NetworkInformation.GetIsNetworkAvailable() returns false. Always remember: from your NetworkAddressChanged handler, you must query GetIsNetworkAvailable to definitively find out the connectivity situation. </p> <p>Other gotchas include the “illusion of connectivity”. This happens when you have some connectivity (say you’re on a WiFi network in an airport or a coffee shop) but not any Internet connectivity until you sign in or pay up. Your app may see GetIsNetworkAvailable return true, but should still try that actual outbound request to ascertain this.</p> <p>In some cases virtual machines (e.g. Hyper-V running on your Windows Server or running Windows with Parallels on your Mac) may interfere with this feature and your app may see false positives. </p> <p>---</p> <p>Previous posts in this series:</p> <ul> <li><a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">Introducing Offline and Out of Browser support in Silverlight</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-support-what.html">Silverlight out-of-browser support: What kind of apps can you build?</a> </li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-install.html">Silverlight out-of-browser apps: The Install</a></li> <li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-launch.html">Silverlight out-of-browser apps: Launch</a></li> </ul> <p>Related links:</p> <ul> <li><a href="http://videos.visitmix.com/MIX09/T78M">Peter Smith’s “Offline network detection in Silverlight” talk from Mix 09</a></li> <li><a href="http://blogs.msdn.com/ncl/archive/2009/03/24/code-patterns-for-online-offline-network-detection.aspx">Code patterns for Online/Offline Network Detection</a></li> </ul>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-6810771.post-19217761485031907752009-04-21T18:13:00.001-07:002009-07-10T19:22:01.671-07:00Silverlight out-of-browser apps: Launch<p>Silverlight 3 offline/out-of-browser apps maintain a sticky presence on your desktop upon the initial detach (install) operation. They can be looked up and launched in an experience not unlike the one you see with conventional desktop applications. You can search for and find these apps using OS search utilities (Windows desktop search, Spotlight on OS X) where they show up in as Programs.</p><h4>Application id</h4><p>Silverlight uses some indirection from the shortcut to the real app binaries on Windows (however on the Mac, the bundle created on install <em>is</em> the app, with limited metadata squirreled away in the <em>offline application cache</em>). This isn’t because we drink the “architecture astronaut” kool-aid on indirection, rather because doing so in this case allows us to add runtime logic around housekeeping which is effective when updates for the app or runtime exist. If you deconstruct the shortcut to a Silverlight out-of-browser app on Windows, you’ll find a command like this:</p><p></p><pre style="WIDTH: 448px; HEIGHT: 56px">“C:\Program Files\Microsoft Silverlight\<<em>version</em>>\<br /> sllauncher.exe <<em>app id</em>>” </pre><br /><p>Ignore the newlines above. You’ll notice that the app id is a string made with the union of the domain of origin and some random number/text e.g. www.mysite.com.3509. During install on Windows, Silverlight creates a directory hive within your user profile so it can store the app binaries along with other metadata. It also assigns the app an identifier which is unique for a specific user on that machine. It appends this id into the shortcut, wherever the app is to be referenced. </p><br /><h4>The app launch sequence</h4><p>When the shortcut is activated, the command is run, and as a result, sllauncher.exe is launched with that app id as argument. The launcher is a container program that chiefly handles the windowing logic for the app, while instantiating and deferring to Silverlight the specific function of loading and running the app. Among the things the launcher controls are the window adornments like icon and title text, a settings such as position. This is just scratching the surface. In future we expect to provide more window customization.</p><br /><p>When sllauncher.exe hosts Silverlight, the runtime does a reverse lookup of the XAP file using the app id, additionally collects all metadata persisted in the offline application cache and then initializes Silverlight core services to the provenance URI of the XAP. This is the app’s original site of origin, not the location it was loaded off disk. This cascades into the correct (i.e. original) networking and security settings being applied to the app. All <a href="http://nerddawg.blogspot.com/2008/03/silverlight-2-demystifying-uri.html">fallback lookups for relative URIs</a> get resolved against the right base URI. All policy settings for cross-domain and cross-scheme access get applied properly; and the app has access to the same local persistence store (Isolated Storage) as its in-browser sibling. If not for the ExecutionState data exposed by the Silverlight runtime, the app would “think” it was running within the browser like it did prior to install. If updates to the XAP were successfully downloaded in a previous app launch, Silverlight will scavenge the old bits and use the updated bits instead. It is now ready to launch the app.</p><br /><h4>Was the app locally activated?</h4><p>Upon launch, Silverlight applications can detect whether the current activation was from within a browser, or locally as a standalone window (aka out of browser). This is done by looking at the RunningOffline property of the Application type. When the value is true, the app was locally activated. When false, the app was activated via an OBJECT tag within a web page in the browser.</p><br /><div style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 1pt; PADDING-LEFT: 4pt; PADDING-RIGHT: 4pt; BACKGROUND: #fdffe5; MARGIN-LEFT: 0.05in; BORDER-TOP: windowtext 1pt solid; MARGIN-RIGHT: 0.05in; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 1pt; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt"><p style="MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="color:blue;">public</span> <span style="color:blue;">partial</span> <span style="color:blue;">class</span> App : <span style="font-size:0;">Application</span> </p><p style="MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code">{</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="color:blue;">public</span> App () </p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code">{</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span>...</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span><span style="color:blue;">this</span>.Startup +=<span style="mso-spacerun: yes"> </span><span style="color:blue;">this.</span>App_Startup;</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code">}</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"></p><p></p><p></p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="color:blue;">void</span> App_Startup(<span style="color:blue;">object</span> sender, <span style="font-size:0;">StartupEventArgs</span> e) </p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code">{</p><p style="MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-tab-count: 1"></span><span style="mso-spacerun: yes"> </span><span style="color:blue;">if</span> (Application.Current.IsRunningOutOfBrowser) </p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span>{</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-tab-count: 1"></span><span style="mso-spacerun: yes"></span>this.RootVisual = new OutOfBrowserPage();</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span>} </p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span><span style="color:blue;">else </span><p></p><p></p><p></p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span>{</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span><span style="mso-tab-count: 1"></span><span style="mso-spacerun: yes"></span>this.RootVisual = new PageToBeDisplayedInBrowser();</p><p></p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"><span style="mso-spacerun: yes"></span>}</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code">}</p><p style="TEXT-INDENT: 0.45in; MARGIN: 0in 0in 0pt; BACKGROUND: #fdffe5" class="Code"></p><p>}</p></div><br /><p></p><br /><del><p>Note: we’re changing API names to better reflect behavior; so expect the code snippet to change with Silverlight 3 RTW, but the principles will more or less remain true.</p></del><br /><p>In the next post we will look at network awareness in offline/out-of-browser Silverlight apps. See you then.</p><br /><p>Previous posts in this series:</p><ul><br /><li><a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">Introducing Offline and Out of Browser support in Silverlight</a></li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-support-what.html">Silverlight out-of-browser support: What kind of apps can you build?</a></li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-apps-install.html">Silverlight out-of-browser apps: The Install</a></li></ul><p></p><p>[Update 10-Jul-09]: Code snippets updated for Silverlight 3 RTW.</p>Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-6810771.post-72699569554802997172009-04-12T12:15:00.000-07:002009-07-10T19:06:49.964-07:00Silverlight out-of-browser apps: The Install<p>There are three main pillars to the new offline and out-of-browser feature set in Silverlight. These pillars are also tied to user experience; namely Install, Launch and Manage. In additions there are framework-level APIs and behind the scenes support from the runtime for a plethora of things that cross-cut these 3 pillars.  </p><p><a href="http://4.bp.blogspot.com/_vO3QC5qlK78/SeI-M77MnyI/AAAAAAAAAEI/o-wOwFuYuYk/s1600-h/SL3OOBPillars.PNG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 212px;" src="http://4.bp.blogspot.com/_vO3QC5qlK78/SeI-M77MnyI/AAAAAAAAAEI/o-wOwFuYuYk/s320/SL3OOBPillars.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5323886101470682914" /></a>In this post we will look specifically at the Install operation.</p><p>A Silverlight app needs to be specially crafted for that out-of-browser function. There’s not much to it really: the application manifest (AppManifest.xaml) should be adorned with the <code>OutOfBrowserSettings</code> element which declares such metadata on the app as short name, window title, blurb and icons. No worries, tools make this easy for you via the Silverlight application project properties pane. Silverlight treats the presence of this element as an indication from the app author for opt-in to the out-of-browser feature set. Only this class of apps can be “installed”.</p><p>The install operation itself can be achieved in one of two ways:</p><ul> <li>via platform UI on the context menu that says <em>“Install {app short name} onto this computer…”</em></li> <li>via app driven UI which calls the <code>Install()</code> method on the Application type</li></ul><p>Implicit in either case is the fact that install is required to be a user-initiated operation. And that too user-initiated within the Silverlight display surface on a web page. This allows us (building the runtime and platform) to better control the user experience and guarantee predictability, security etc.</p><p>Further, Silverlight apps cannot be installed without the consumer end user specifically consenting to this action. This removes the element of surprise. We’ve tried to maintain consistency with the experience one intuits on a particular operating system, while also balancing the needs of Silverlight app authors and our own user experience goals. As a result, you will see different UX on Windows and Mac – each appealing to its demographic. </p><br /><p>On Windows, Silverlight shows an application modal dialog like this, seeking the user’s permission to proceed:</p><p><a href="http://3.bp.blogspot.com/_vO3QC5qlK78/SeI-iR3xbUI/AAAAAAAAAEQ/LWs9xzStIzY/s1600-h/SLoobConsentDefaultIcons.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 145px;" src="http://3.bp.blogspot.com/_vO3QC5qlK78/SeI-iR3xbUI/AAAAAAAAAEQ/LWs9xzStIzY/s320/SLoobConsentDefaultIcons.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5323886468139150658" /></a>The dialog is modeled as a confirmation dialog, and the user is asked to allow or deny permission in context, with the assertion <em>“You are installing {app short name} from {domain of origin}”</em>.  </p><p><a href="http://3.bp.blogspot.com/_vO3QC5qlK78/SeI-3BpWF4I/AAAAAAAAAEY/scCrsM17Jr4/s1600-h/SLoobInstallMac.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 146px;" src="http://3.bp.blogspot.com/_vO3QC5qlK78/SeI-3BpWF4I/AAAAAAAAAEY/scCrsM17Jr4/s320/SLoobInstallMac.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5323886824560924546" /></a></p><p>The astute reader will notice that the dialogs are similar across Windows and Mac OS X – at least in principle – but each adheres to the native OS theme. The Mac dialog does not seek shortcut preferences, given that Mac users are expected in the very next step to drag the out-of-browser app bundle into a location of their choice, much like they would when installing another application.</p><p>A dialog of the form above is shown when the app declares no icons of its own. You see the “fallback” icon shown by the runtime.  When the app declares its own brand icon, Silverlight will gladly display it at install time, as the following screenshot of the dialog on Windows attests: <a href="http://2.bp.blogspot.com/_vO3QC5qlK78/SeI_DUr0gFI/AAAAAAAAAEg/01ElOYDvv7g/s1600-h/SLoobConsentAppIcons.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 145px;" src="http://2.bp.blogspot.com/_vO3QC5qlK78/SeI_DUr0gFI/AAAAAAAAAEg/01ElOYDvv7g/s320/SLoobConsentAppIcons.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5323887035830009938" /></a>If the install were initiated via the <code>Install()</code> method call on the UI thread, the method would synchronously block until the consumer end user made their decision. If they declined, the method returns false; otherwise true. The other install related activities happen asynchronously. The platform signals this to the app via the <code>InstallStateChanged</code> event and the <code>InstallState.Installing</code> state; it inducts the XAP, along with some metadata and housekeeping information into the offline application cache within the user’s profile dir. When this is successfully completed, the platform raises the <code>InstallStateChanged</code> event with the <code>InstallState.Installed</code> state. This is the official notification to the hitherto in-browser app that its out-of-browser copy has been installed. The out-of-browser app gets a higher default quota (25MB to the previous 1MB) within Isolated Storage for its local data persistence needs. The in-browser and out-of-browser apps share this Isolated Storage with each other. We’re not yet sure if the magic number of 25MB is the right one (or if there is in fact any right value); it is however orders of magnitude higher than the default for in-browser apps and we hope it will open up new scenarios and result in the proverbial 80% of our apps not having to ask the consumer user for a quota increase yet again.</p><p>Upon successful install, Silverlight auto-launches the newly installed app – all sandboxed, out of the browser, and ready to go! The salient points of this Install operation are:</p><br /><ul> <li>keep it lightweight</li> <li>showcase the app brand, not the technology powering it</li> <li>keep the decision simple for the consumer, and in context</li> <li>get the consumer to their desired goal in the shortest time possible i.e. launch the app upon install</li></ul><br /><p>More about the story behind the Launch experience in the next post. Until then, cheerio, toodle-ooh and all that.</p><br /><p>Related posts:</p><ul><li><a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">Introducing Offline and Out of Browser support in Silverlight</a></li><li><a href="http://nerddawg.blogspot.com/2009/04/silverlight-out-of-browser-support-what.html">Silverlight out-of-browser support: What kind of apps can you build?</a></li></ul><br /><br />[Update 10-Jul-09] API names updated to reflect Silverlight 3 RTWUnknownnoreply@blogger.com4tag:blogger.com,1999:blog-6810771.post-57588420907344494982009-04-01T19:51:00.001-07:002009-04-01T20:00:42.575-07:00Silverlight out-of-browser support: What kind of apps can you build?<p>This is first in my series of technical drilldown posts on the new offline and out of browser support in Silverlight 3.</p><p>It is something of a tradition in Microsoft to list out scenarios when a new feature set is being conceived. This practice is by no means unique to this company. I feel that doing so establishes a common baseline and taxonomy which immensely helps as the concept matures and gains complexity. Typically these scenarios are fleshed out in functional specifications. </p><p>In this post, I summarize the flavors of apps and scenarios that are enabled by the new offline and out of browser support in Silverlight 3. Most of these are self-explanatory and so using another Microsoft tradition, I will stick to concise bullet points rather than prose. A list similar to the one below in fact was used by our crew when we started our planning for this feature set a few months ago:</p><h3>Connectedness</h3><h4>Fully disconnected app</h4><ul><li>App has no networking needs </li><li>Reliance on Silverlight just as an installation vehicle for the app </li><li>We don’t expect this will be very common </li></ul><h4>Occasionally connected app</h4><ul><li>App is resilient to network outage </li><li>Conditionally persists data into iso store or cloud based on network availability </li><li>This is the sweet spot for our feature offerings and where most of our attention goes </li></ul><h4>Connected app</h4><ul><li>App uses the offline feature set only for the sticky desktop presence </li><li>We don’t expect this will be very common </li></ul><h4></h4><h3>User experience</h3><h4>App behaves exactly the same in browser and out</h4><ul><li>App author wants to deliver the same experience in either case </li><li>“Try before you buy”, “Get more features upon install” and other such progressively enhanced SKU situations </li><li>Our data suggests consumers find comfort in apps that – in broad brushes – seem similar OOB as when they did in-browser </li></ul><h4>App shows different UI in-browser and out-of-browser</h4><ul><li>App author wants to exploit the real estate available in standalone window </li><li>Browser page could have limited functionality which lights up only upon detach </li><li>Browser page shows only the “Install” badge and the “real” UI only shows up when launched out of browser </li></ul><h4></h4><h3>Approach</h3><h4>Porting an existing Silverlight 2 app to run offline/out-of-browser</h4><ul><li>Even though the feature is a new addition to SL3, <em>some</em> SL2 apps can benefit from it </li><li>Requires no changes to code and no rebuilds </li><li>Can be done as a post-production step by modifying the manifest and optionally adding icons into the XAP</li><li>Build disconnected and connected apps, but not occasionally connected </li></ul><h4>Building a new offline/out-of-browser app </h4><ul><li>Our mainline scenario </li><li>Leverage everything the offline/out-of-browser feature set and the rest of Silverlight has to offer </li><li>Build disconnected, connected and occasionally connected apps</li></ul><p></p><p>In the next post, we will look at the pillars of this feature, starting with the install (a.k.a detach) operation.</p><p>Related posts:</p><ul><li><a href="http://nerddawg.blogspot.com/2009/03/introducing-offline-and-out-of-browser.html">Introducing Offline and Out of Browser support in Silverlight</a></li></ul><p></p>Unknownnoreply@blogger.com8tag:blogger.com,1999:blog-6810771.post-71586650650534668342009-03-18T09:39:00.001-07:002009-07-25T15:18:24.950-07:00Introducing Offline and Out of Browser support in Silverlight<p>Today we are making a radical upgrade to your web experience with Silverlight 3’s support for offline and out of browser apps. App authors can now build one app that works in the browser and out; at home, at work or on the go. </p> <p>Among the new set of features enabling this experience are:</p> <ul> <li><strong>Sticky presence on the desktop</strong>: Upon user consent, a Silverlight app can be detached and pinned on the user’s desktop using familiar OS metaphors for this action. On Windows this can be through Start menu and/or Desktop shortcuts. On the Mac the user can drag and drop the application bundle to a location of their choice.</li> <li><strong>Run outside of browser</strong>: activating the app locally launches it outside of the web browser. Our data suggests consumers find this more intuitive as a result of clicking on a desktop shortcut.  </li> <li><strong>Safe by default</strong>: Silverlight still retains a rigid security sandbox within which the app operates. Apps <strong>cannot</strong> elevate beyond the privileges granted by this sandbox. Our philosophy is to stretch this sandbox by providing features within it on a case by case basis. More on this in future.</li> <li><strong>Non-administrative install</strong>: Along with the sandbox, Silverlight furthers the consumer’s security by never requiring administrative privileges either for install or for run. An exception may be if optionally a user on the Mac wants to drop the app bundle into a dir that requires sign-on. In that case Silverlight honors the framework set out by the OS and user intuition.</li> <li><strong>Higher default persistence space</strong>: the default quota for Isolated Storage for Out of Browser apps is a higher value than for browser based apps. It is currently 25MB.</li> <li><strong>Network awareness</strong>: One of the key ingredients of this feature set is the ability for Silverlight apps to be aware of network connectivity and to be notified when that changes. Apps can cache data (or outbound calls) into Isolated Storage and post-back (or playback) when connectivity is regained. This works in Silverlight apps in the browser and out.</li> <li><strong>Built-in auto update</strong>: Silverlight will check for new versions of the app asynchronously upon app requesting such a check, guaranteeing users an instant-on experience. Updates are applied at next launch, providing apps complete control over when and how frequently updates are applied with Silverlight doing all the heavy lifting.</li> <li><strong>Execution state notifications to the app</strong>: Silverlight notifies the app on momentous events throughout its lifetime and transition from in-browser to out-of-browser, allowing the app to model its UI accordingly.</li> </ul> <p>A short note on our philosophy before I end: When my team and I originally started thinking about delivering this feature set, we were absolutely certain about some things. Namely that this would be inherently a part of Silverlight, requiring no new runtimes/frameworks, no additional downloads, no new learning curve for app authors, no security elevations for consumer installs. That is the Carmot, if you will, in our offline and out of browser support. We’re also introducing a user experience that – in my biased opinion – fits well with the rest of the web; a model that allows consumers to try before they install; a model that takes an app familiar to them on the Web and makes it a companion on their desktop. Contrast that a model that requires consumers to have “install intent” and click on a hyperlink or a badge in good faith to experience an app they haven’t hitherto seen. There’s certainly a place for that install model and we’ve supported that in other products in the past for non-Web scenarios. And finally, I’m closely watching where support for offline applications in HTML5 goes and how mainstream browsers adopt it. At some point I do want our model to co-exist with the experiences they introduce.</p> <p>Developers can <del>evaluate and play with the <a href="http://silverlight.net/getstarted/silverlight3/default.aspx">Silverlight 3 Beta</a></del> build these apps <a href="http://silverlight.net/getstarted/">using Silverlight 3</a> right now. There's great runtime and tools support.</p> <p>In future posts, I will be introducing this feature set from a technical perspective.</p> <p><strong>Post script</strong>: You can now understand why there’s been radio silence on this blog for months. This feature took a lot of Mountain Dew, sweat and tiers from a couple handful of the best darned engineers in the world. And a lot of questions, comments, critiques and feedback from the best darned customers a product can have. Here’s to takeoff and the EAP!</p><br /><br />[Update 10-Jul-09] Auto-update section modified based on changes post beta; now reflective of Silverlight 3 RTW behavior<br />[Update 25-Jul-09] Links updated to Silverlight 3 RTWUnknownnoreply@blogger.com14tag:blogger.com,1999:blog-6810771.post-13726147747090750302008-10-28T14:32:00.000-07:002009-04-15T16:58:18.989-07:00Search Engine Optimization for Silverlight applications<p>My whitepaper on <a href="http://silverlight.net/learn/whitepapers/seo.aspx">Search Engine Optimization for Silverlight </a>is now online: <a href="http://silverlight.net/learn/whitepapers/seo.aspx">http://silverlight.net/learn/whitepapers/seo.aspx</a><br /><br />It provides a story for Silverlight 2 application authors and publishers who want their apps and content to show up in search engine results pages (SERPs) today.<br /><br />Downloadable copies are here on the MS Download Center:<br /><a href="http://download.microsoft.com/download/1/d/7/1d7ac97c-dd36-4d89-bb64-7f1858328850/Search%20Engine%20Optimization%20for%20Silverlight%20Applications.doc">Word Doc</a> | <a href="http://download.microsoft.com/download/1/d/7/1d7ac97c-dd36-4d89-bb64-7f1858328850/Search%20Engine%20Optimization%20for%20Silverlight%20Applications.xps">XPS </a> | <a href="http://download.microsoft.com/download/1/d/7/1d7ac97c-dd36-4d89-bb64-7f1858328850/Search%20Engine%20Optimization%20for%20Silverlight%20Applications.pdf">PDF</a></p><p>Thanks to Dan Penn, Jon Rooney and Nitya Ravi for all their help in getting this off the ground.</p>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6810771.post-56889958953963877332008-09-26T08:38:00.000-07:002008-09-26T08:47:13.298-07:00Silverlight 2 RC0: Here's what's new<p>The <a href="http://silverlight.net/GetStarted/sl2rc0.aspx">Silverlight 2 release candidate </a>build has been released to developers so they can prepare for the upcoming release to web (RTW) of the product, and migrate their Beta 2 applications forward. This build has a number of functional, performance and stability related bug fixes. We’ve had to making some <a href="http://download.microsoft.com/download/6/f/e/6fe1f43d-9d0c-4346-ad08-602df9bcb3cf/BreakingChangesBetweenBeta2andRelease.doc">breaking changes </a>along the way. There are also a few new features (which explains the silence on this blog and others like it, over the past few weeks). Here’s an incomplete list:<br /></p><p><strong>Per-frame callbacks<br /></strong>Create physics animations or override the animation system by hooking up for the CompositionTarget.Rendering event.<br /></p><p><strong>Controls<br /></strong>PasswordBox, ComboBox (well, a non-editable dropdown list only for now), MessageBox and ProgressBar.<br />Updated look and feel for controls.<br />IsEnabled and IsEnabledChanged added to the Control type.<br />Exposed virtual On* events on Control e.g. OnGotFocus, OnKeyDown, OnKeyUp, OnMouseEnter etc.</p><p><strong>Support for popping up windows</strong><br />Use the HtmlPage.PopupWindow API, in association with the new AllowHtmlPopupWindow param on the OBJECT tag to open a URI in a new browser window upon a user-initiated action. Note: doesn’t work on Safari because it doesn’t implement the right NPAPI contracts for this.<br /></p><p><strong>Accessibility<br /></strong>Improvements in accessibility and UI automation on Silverlight controls. </p><p><strong>Networking<br /></strong>Support for making HTTP requests on background threads.<br />Upload support added to WebClient.<br />Support for percent escaped internationalized URIs for remote endpoints.<br /></p><p><strong>Input<br /></strong>A new LostMouseCapture bubbling event for when you lost capture.<br />Support for global keyboard character input into a TextBox (diacritics, non-ASCII characters etc.) </p><p><strong>Resources<br /></strong>Extended the kinds of things that can be designated as application or element level resources e.g. Color, FontFamily, TextAlignment and many many more.<br /></p><p><strong>XAML<br /></strong>Default value support for custom dependency properties via PropertyMetadata.<br />Support for object element syntax for StaticResource.<br /><br /></p><p>With this release, the Silverlight 2 product is feature complete. Absent any major last-minute fire drills, the public surface area (APIs) in this RC should mirror the upcoming RTW product. Thank you for helping us build this product. Your feedback has been our magnetic north. Just a few more days until the ship sails…! </p>Unknownnoreply@blogger.com8tag:blogger.com,1999:blog-6810771.post-37455970212762826912008-07-23T20:55:00.000-07:002008-07-23T21:04:11.023-07:00Death, Taxes and LatencyBy the time Silverlight came around, the problems afflicting web applications all round were well known and somewhat well understood. The burden of dealing with network latency, cancellation and errors should not be thrust on every web developer. Platforms have a unique role in abstracting away these problems. However, beyond band-aid solutions, web platforms haven’t provided any effective remedies. With Silverlight we’ve tried to tackle these head on. I wouldn’t say we’ve solved them, but we’re a ways ahead than many others out there in recognizing and fixing issues in this space. <br /><br />Our strategy involves giving fish as well as fishing lessons. Silverlight enforces an asynchronous programming model for just about every latency, cancellation or conflict -afflicted scenario your web app would encounter. We further the mindset that much everything you’re trying to access can be on a remote machine or can take forever to return or can simply fail. This defensive posture is critical. And so whether it is invoking and consuming a web service, or modifying the UI from off-thread, there is an API in Silverlight that does this asynchronously. We go further though. Aside from areas where it simply must be compatible with prior art in Windows Presentation Foundation (WPF), it is de jure for events in Silverlight to be async. As of Beta 2 I can only think of layout events as being synchronous a.k.a. blocking and at least one more I can’t talk about just yet being added in RTW.<br /><br />The novice developer may encounter a bit of friction in learning how to code to this asynchronous programming model. But there is friction in learning that Ctrl+Alt+Del unlocks a Windows machine, but you master it pretty quickly, and it becomes muscle-memory after a while. Likewise, we hope you will master async coding soon enough and be on your way to building web apps the way they were meant to. You and your app consumers will be the better off for it.<br /><br />Another axis to this is the provision of tools and user experience options in Silverlight around async coding. This includes the options of using BackgroundWorker, multi-threading, splash screens and other forms of progress indication. Whatever your expertise, there’s an option available for you.<br /><br />Still another axis is the defensiveness in the platform to counter issues like reentrancy. Silverlight has a reentrancy guard which will throw a Null AV (resulting in a process shutdown) if it detects reentrant behavior such as a draw call from within an existing draw call. You can be sure to catch these things at development time, rather than deal with them at runtime.<br /><br />Given the ambient environment where Silverlight is hosted and run, the runtime needs to deal with problems such as message pumping and reentrancy arising from STA threads. Besides it doesn’t own its own UI thread – the browser does. Async patterns really shine here. Please tell us how we’re doing in this area. Has the predominantly async model been a hindrance in your development or had you not noticed until you saw this blog post?<br /><br />Remember, like death and taxes, latency issues afflict all who build apps for the web. Asynchrony fixes one of those.Unknownnoreply@blogger.com13tag:blogger.com,1999:blog-6810771.post-43568777722652543822008-06-08T18:00:00.001-07:002008-06-16T06:10:34.908-07:00Pages in Silverlight<p>Pages as a paradigm likely pre-date the web itself although they have been popularized by document-based markup languages deriving from SGML. Windows Presentation Foundation (WPF) with XAML further codifies Pages as a first-class UI element from its heretofore usage as a logical element. Looking back from Silverlight, this is as good a point in history to start as any. WPF has built-in support for reusable pages in its applications, and the task of navigation between them. It provides the infrastructure for declarative navigation via hyperlinks or programmatic navigation via <a title="NavigationService in WPF" href="http://msdn.microsoft.com/library/system.windows.navigation.navigationservice.aspx">NavigationService</a>, and a journal that remembers which pages were navigated to or from. For XBAPs on IE7+, WPF supports integration of the journal with the browser's Back and Forward buttons, while elsewhere it displays a substitute navigation bar with this functionality (the limitation is an effect of how the XBAP host plugs into the browser). There is also a building block called PageFunction which introduces a paradigm for invoking pages as if they were methods, providing a neat little way to build wizard UI. Unlike WPF, Silverlight does not support these things, as of version 2. This post isn't about brooding that absence though -- instead we'll look at the lay of the land in Silverlight 2 with regard to pages and navigation, and look at common workarounds.</p><p>Although Silverlight does not have the Page type at this time, the term is currently used for its root visual UserControl. That root visual object is analogous to the root window in WPF, can only be set once for the lifetime of the app, and is effective once the Application's Startup event is raised. The act of navigating from one page to another is similar in principle to the act of removing one child element from an invisible root and adding another child in its place. [Actually given the journal it is more like switching Z-indices between siblings, so that one gets prominence while the other is made inconspicuous]. You can use this same principle in devising the notion of paging in a Silverlight app.</p><br /><p>This recipe requires the following ingredients:<br /></p><ul><li><strong>App.xaml.cs</strong>: the code-behind for the Application</li><br /><li><strong>Frame.cs</strong>: a user control which will serve as our "navigation frame". This has no UI.</li><br /><li><strong>Page1.xaml</strong>/<strong>Page1.xaml.cs</strong>: a user control representing a unique "page". This has a button whose click event navigates away to Page 2.</li><br /><li><strong>Page2.xaml</strong>/<strong>Page2.xaml.cs</strong>: similar to Page 1 in logic and function, only this represents the second page in your app. </li></ul><br /><p><strong>Step 1: Create a navigation frame</strong></p><p>This is a really simple user control. It has a public Navigate method which is passed a "page" object for which it duly resets its original content. </p><pre><div style="font-family:monospace;font-size:10pt;">// Contents of Frame.cs</div><div style="font-family:monospace;font-size:10pt;"> </div><div style="font-family:monospace;font-size:10pt;">public class NavigationFrame : UserControl { </div><p> // Navigate the frame to the specified content<br /> public void Navigate(UIElement content)<br /> {<br /> // the existing content of this user control is<br /> // discarded and the specified param is plugged in<br /> // its place<br /> this.Content = content;<br /> }<br /> } <p> // Optional abstraction for page config<br /> public static class Pages<br /> {<br /> // for simplicity we're using static properties,<br /> // but this could just as easily be a URI to<br /> // Type mapping table<br /> public static UserControl HOME_PAGE = new Page1();<br /> public static UserControl ANOTHER_PAGE = new Page2();<br /> }</p><p> </p></pre><br /><p><strong>Step 2: Wire up the navigation frame as the app's RootVisual</strong></p><p>Ordinarily the code generated by Silverlight tools (Visual Studio or Blend) will have a user control hooked up as Application.RootVisual within the Startup event handler. You will change this to hook up the navigation frame. Then hook up the user control to be the navigation frame's content (by invoking the NavigationFrame.Navigate method you created above).</p><pre><div style="font-family:monospace;font-size:10pt;">// Contents of App.xaml.cs</div><p>// the Startup event handler sets the root visual<br />private void App_Startup(object sender, StartupEventArgs e)<br />{<br /> // Navigate to home page<br /> Navigate(Pages.HOME_PAGE);<br />} <p>public void Navigate(UIElement content)<br />{<br /> // Create frame on an as-needed basis<br /> if (this.frame == null)<br /> {<br /> this.frame = new NavigationFrame();<br /> this.RootVisual = this.frame;<br /> } <p> // Navigate to content<br /> this.frame.Navigate(content); <p>} <div style="font-family:monospace;font-size:10pt;"><span style="color:blue;"></span> </div></pre><br /><p><strong>Step 3: Build your pages</strong></p><p>Now that the navigation infrastructure is ready, go ahead and create a couple pages. These are merely user controls which would otherwise have been hooked up directly as the RootVisual. That part is simple. An important attribute in this equation is the fact that pages need to provide the experience of "navigating away". You can use a hyperlink, a button, or trap mouse/key events. We'll use a button and insert the navigation logic in it's click event handler.</p><br /><pre><div size="10pt" face="monospace"><span style="color:blue;"></span>// Contents of Page1.xaml.cs </div><p>// on btn click, this navigates to the second page<br />private void navigateButton_Click(object sender,<br /> RoutedEventArgs e)<br />{<br /> (Application.Current as App).Navigate(Pages.ANOTHER_PAGE);<br />}<div size="10pt" face="monospace"><span style="color:blue;"></span></div><div size="10pt" face="monospace"><span style="color:blue;"></span> </div><div style="FONT-SIZE: 10pt; FONT-FAMILY: monospace"> </div></pre><br /><p>Let's create another user control which will be <em>navigated to</em>.</p><br /><pre><div style="FONT-SIZE: 10pt; FONT-FAMILY: monospace"><span style="color:blue;"></span>// Contents of Page2.xaml.cs </div><p>// on btn click, this navigates to the first page<br />private void navigateButton_Click(object sender,<br /> RoutedEventArgs e)<br />{<br /> (Application.Current as App).Navigate(Pages.HOME_PAGE);<br />}<div size="10pt" face="monospace"><span style="color:blue;"></span></div><div style="FONT-SIZE: 10pt; FONT-FAMILY: monospace"><span style="color:blue;"></span> </div><div style="FONT-SIZE: 10pt; FONT-FAMILY: monospace"> </div></pre><br /><p>Well, that's all there is to it really. Build and run, and you've got your simple little navigation application.</p><p>In this pattern, the <em>navigation frame </em>element:</p><ul><br /><li>is the equivalent of the implicit navigation control </li><br /><li>is a container with no visible visual properties (e.g. Background, etc.) </li><br /><li>has only a Content element representing the current page </li><br /></ul><a href="http://2.bp.blogspot.com/_vO3QC5qlK78/SEyBjfd-YbI/AAAAAAAAACQ/M2yqJdU9kFE/s1600-h/SilverlightNavigationApplication_ClassDiagram.png"><img id="BLOGGER_PHOTO_ID_5209681315703447986" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_vO3QC5qlK78/SEyBjfd-YbI/AAAAAAAAACQ/M2yqJdU9kFE/s400/SilverlightNavigationApplication_ClassDiagram.png" border="0" /></a><br /><p>In the pattern, the <em>page</em> element:</p><ul><br /><li>is the equivalent of the navigable Page </li><br /><li>has visuals or contains visual elements </li><br /><li>can be attached and detached from the tree on a navigate event (i.e. the current element is removed, and a new one added in its place) </li><br /></ul><p>Our example used the <strong>Navigate By Object</strong> approach. Note that we invoked the Navigate method and passed it a page object. You could tweak the logic so your pages can be given data as part of the Navigate call. You could just as easily add URI-to-type mapping into the Pages utility type. That would allow you to replicate the <strong>Navigate By URI</strong> approach which is more organic to content on the web. If you use the Navigate By Object approach and you have a journal that maintains a back/forward stack of pages you've previously navigated to, you can incur a working set hit. This is because your journal will retain references the page objects in memory for long intervals - usually the life of the app - preventing the garbage collector from reclaiming them. Using the Navigate By URI approach in such situations can offer better use of memory. This is because you can delay instantiation of page objects until when the Navigate needs to happen.</p><br /><p>In closing, there is a good case for pages, navigation service, journalling, transition animations, deep linking etc. to be part of the Silverlight platform. This is certainly of interest to us as we look toward the next version of the runtime and it's framework. I'd like your thoughts and feedback on these features and how important they are to your scenarios.</p><br /><p>Further reading:</p><ul><li><a href="http://msdn.microsoft.com/en-us/library/ms750478.aspx">Navigation overview in WPF</a> </li><br /><li><a title="Page in WPF" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.page.aspx">Page</a>, <a title="Hyperlink control in WPF" href="http://msdn.microsoft.com/en-us/library/system.windows.documents.hyperlink.aspx">Hyperlink</a> and <a title="Navigation Service in WPF" href="http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.aspx">NavigationService</a> </li><br /><li>Jesse Liberty: <a href="http://silverlight.net/blogs/jesseliberty/archive/2008/05/31/multi-page-applications-in-silverlight.aspx">Multi-page applications in Silverlight</a></li><br /><li>Dave Relyea: <a href="http://blogs.msdn.com/devdave/archive/2008/06/13/navigation-with-transition-effects.aspx">Navigation with Transition Effects</a></li><br /></ul><br /><p><span style="font-size:78%;">PS: For </span><a href="http://nerddawg.blogspot.com/2008/03/silverlight-2-application-model.html#c7743351203048741566"><span style="font-size:78%;">Ben</span></a><span style="font-size:78%;">. Sorry this has been long overdue.</span></p><p><span style="font-size:78%;">PPS: Thanks to <a href="http://www.mikedub.net/">Michael Weinhardt</a> for valuable insights.</span></p><br /><p><span style="font-size:78%;"><strong>Update [06/16/2008]</strong>: Dave has a new post on navigation with transition effects. Link under the Further Reading section above.</span></p>Unknownnoreply@blogger.com10tag:blogger.com,1999:blog-6810771.post-21346122256216682962008-06-08T13:41:00.001-07:002008-06-08T13:43:10.679-07:00How to tell a Silverlight assembly from a .NET Framework one?<p>Silverlight 2 application code is compiled to Common IL and packaged into assemblies (.dll) which are in turn deflated into a Zip file (container with .xap extension). The IL is a CPU- and platform- independent instruction set. The Silverlight runtime has in it the Core CLR which executes this IL. Given that .NET Framework involves much of the same things save for the .xap packaging, how does one tell between a DLL built for Silverlight versus one for .NET Framework?</p><p>Well, the answer is in one of the security assumptions that Silverlight's Core CLR makes to distinguish a core platform assembly from a transparent code app assembly. The <em>mscorlib.dll</em> in Silverlight is signed with a different key than it's namesake in .NET Framework. This is apparent in it's full name, or specifically it's public key token. </p><p>The public key token for mscorlib in Silverlight is:</p><code>7cec85d7bea7798e</code> <p>while the public key token for mscorlib in .NET Framework is:</p><code>b77a5c561934e089</code> <p>So the trick to sniffing out an arbitrary managed code assembly for its allegiance - Silverlight or .NET Framework - is to look through it's list of referenced assemblies, locate mscorlib and then check the public key token. <a title="AssemblySniffer: Detects whether an assembly was built for Silverlight or .NET Framework" href="http://nerddawg.members.winisp.net/AssemblySniffer/">Here is a sample application</a> that does that.</p>Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-6810771.post-63260739988558938932008-06-05T09:21:00.000-07:002008-06-06T22:45:54.258-07:00Beta 2 of Silverlight 2 has just shippedThe second beta of Silverlight 2 has just been released. The team has been cranking away and there are some new features and lots of bug fixes to show. A big thanks to all who provided vital feedback on our previous pre-releases!<br /><br /><ul><li>Animation <ol><li>Support for animating custom data points </li><li>Object Animation support (animating structs) </li></ol></li><li>Deep Zoom <ol><li>New XML-based file format </li><li>MultiScaleTileSource to wire up your own images and get the Deep Zoom experience </li><li>Better notifications when sub-images enter the view </li></ol></li><li>Controls <ol><li>Customize the look and feel of controls using Visual State Manager. Interactive control templates were never so easy. </li><li>Some base controls are now part of the core platform, rather than packaged into apps. Say hello to smaller app sizes. </li><li>Calendar now supports multi-selection and blackout dates </li><li>New TabControl</li><li>Control properties changes (Background, Tooltip, FontFamily, FontSize…) </li><li>DataGrid improvements: auto size, reorder, sort, performance and more </li></ol></li><li>TextBox <ol><li>IME Level 3 input support </li><li>Text wrapping and multiline selection highlighting in textbox </li><li>Scrolling and clipboard support </li><li>Document level navigation keys </li></ol></li><li>Improvements in error handling, reporting </li><li>Parser and Property system <ol><li>DependencyProperty.Register/RegisterAttached now supports PropertyMetadata </li><li>New DependencyObject.ClearValue </li><li>Visual tree helper </li></ol></li><li>Data-binding <ol><li>Per binding level validation </li><li>Support for element syntax for binding markup extensions </li><li>Binding to attached properties </li><li>ItemsControl extensibility (OnItemsChanged method) </li><li>Fallback in value conversion (Binding.UnsetValue) </li></ol></li><li>Input <ol><li>Support for limited keyboard input in Full Screen mode (arrow, tab, enter, home, end, pageup/pagedown, space). I've seen more than a few requests for this on the forums. </li><li>Managed APIs for Inking and stylus input </li></ol></li><li>Networking and Data <ol><li>Cross Domain support in Sockets </li><li>Cross Domain security enhancements </li><li>HttpWebRequest and WebClient callable from background threads </li><li>Upload support in WebClient </li><li>Isolated Storage: default size increased to 1MB and new ability to change quota with user consent. Also a new management UI. </li><li>Duplex communications ("push" from server to Silverlight client with no need to "poll" for data) </li><li>LINQ -to- JSON serialization </li><li>Significantly improved SOAP interop </li><li>"Add New Item" template in Visual Studio for "Silverlight-enabled WCF Service" </li><li>ADO.NET Data Services support </li></ol></li><li>UIAutomation and Accessibility support in the platform </li><li>Media <ol><li>Platform support for Adaptive Streaming (also referred to by people as multi bitrate), the ability for Silverlight to switch between media depending on network and CPU conditions </li><li>Content protection with PlayReady DRM and Windows DRM </li><li>Basic server-side playlist (SSPL) support </li></ol></li><li>Localization <ol><li>Changes to localized application model. You now create one xap per locale, instead of one monolithic multilingual app </li><li>Expanded localization languages of runtime and SDK </li><li>Japanese SDK Installer and documentation (July 10) </li></ol></li><li>Several changes to make API and behavior more compatible with WPF </li><li>Tools <ol><li>Beta 1 projects will be automatically ported to Beta 2</li><li>Remote debugging for VB on the Mac </li></ol></li><li>CLR <ol><li>A new developer-oriented runtime package with debugging binaries, localized strings, docs etc. </li><li>Support for OS fallback logic for resources </li><li>CurrentCulture and CurrentUICulture isolation to AppDomain level </li></ol></li><li>DLR <ol><li>Performance improvements </li><li>Various new DLR and IronPython 2.0 Beta 2 language features </li><li>Various new IronRuby features </li></ol></li></ul><p>We're not quite done for Silverlight 2, but are getting really close. There's some ongoing work to get more controls delivered (Scott has said the expectation was to ship over 100 controls) at and beyond RTW. I know people have asked for ComboBox and PasswordBox. We'll also have per-frame callback support (CompositionTarget.Rendering event) to light up those physics animation scenarios you're dreaming of, and further accessibility work on controls, improvements to PNG support in imaging, among other things. Needless to say, the focus from here on will be to stabilize and ship a solid product. </p><p>I hope you like what we've cooked. Please <a href="http://silverlight.net/forums">keep that feedback coming</a>. Without you this would not be possible and be quite meaningless.</p><p>Further content:</p><ul><li>Get <a href="http://www.microsoft.com/silverlight/resources/install.aspx?v=2.0">Silverlight 2 Beta 2</a> now!</li><li><a href="http://go.microsoft.com/fwlink/?LinkID=120655&clcid=0x409">Breaking changes between Silverlight 2 Beta 1 and Beta 2</a></li><li>Install <a href="http://go.microsoft.com/fwlink/?LinkId=120319">Beta 2 tools for Visual Studio 2008</a></li><li><a href="http://msdn.microsoft.com/en-us/library/bb404700(VS.95).aspx">Silverlight 2 Beta 2 documentation on MSDN</a></li><li>Scott Guthrie: <a href="http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx">Silverlight 2 Beta 2 released</a></li></ul><p></p>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6810771.post-28510311575341134962008-05-13T19:00:00.001-07:002008-05-13T19:02:37.841-07:00WPF 3.5 SP1: Don't let the SP moniker fool you<p>Yesterday the WPF team shipped some major horsepower features in the vastly understated preview Service Pack to .NET Framework 3.5. It is an exception to the rule for an SP release to have features, and not just bug fixes. In the mold of Windows XP SP2, this SP of .NET Framework 3.5 is chock full of new WPF features.</p> <p>For the first time the .NET Framework has been divided into a Client profile which - intuitively - does not contain server specific libraries such as ASP.NET. This cuts down the size of the .NET Framework to about 25MB (which as Dr. Sneath reminds us is close to Adobe Reader's size) and people like me with a Java background can associate it loosely with the Java SE and Java EE split. In many ways, this is the realization of the Longhorn-era "WinFX" give-or-take a couple assemblies. </p> <p>Given my previous association with the WPF Application Model, I'll begin with a shout out to improvements from and driven by that crew. The Web Browser control in WPF is embodied by the Frame element. There's new support for interop between WPF and HTML content hosted within it (<em>yay for DOM and script access!</em>). In addition to the existing support for rendering HTML content via URI comes new support for rendering HTML via a stream. This allows for dynamically created HTML content to be rendered in a WPF app. And oh, XBAP enthusiasts will note that this all works in the partial trust sandbox. The progress UI on XBAP launch gets a perf boost and is now an instant-on UI. There's wide ranging real and perceived perf enhancements in the product that customers will truly love. Besides, there are some ClickOnce improvements allowing you to customize the activation error experience, suppress/customize the ClickOnce UI, set up file associations (<em>yes, despite my reservations to this</em>), opting out of signing your apps (<em>I've long maintained that shelling out 300 bucks for a cert is good news for Verisign and gang but bad tidings for hobbyist developers; good to see this change</em>) but with support for corps to block unsigned apps (<em>so this is a wash security-wise</em>). And yeah, ClickOnce-deployed apps can be launched with a click of a hyperlink on Firefox!  </p> <p>An update to Visual Studio 2008 now lets you target your apps specifically to this Client profile of .NET Framework. You have an option of packaging up your app in an installer which will bootstrap .NET Framework 3.5 and uses some nifty tricks (like asynchronous NGEN) to speed up the time between the click and bits showing up on screen.</p> <p>This release contains the graphics features demoed at Mix 08, like extensible shader effects which will let you harness the power of the GPU while still using animation, data-binding, media, composition and other WPF goodness. Fittingly, as has been WPF's charter, these features bring advanced concepts like <a href="http://msdn.microsoft.com/en-us/library/bb509561(VS.85).aspx">HLSL effects</a> and <a href="http://en.wikipedia.org/wiki/SIMD">SIMD processing</a> to the realm of application developers like me with simple abstractions and none of the complexity (I mean creating an effect is still the realm of experts, but using it is as simple as instantiating a control in WPF which I'm perfectly capable of doing, equating it with something like a DataGrid). Besides, there's deeper DirectX integration so you can blend or overlay D3D content with WPF.</p> <p>There's a new DataGrid and Office Ribbon control provided out of band with WPF. </p> <p>I can go on and on, but I should stop now because I can't hold this smile much longer. The WPF and other partners contributing to .NET Framework kick some major bootay with this release. Calling it a Service Pack is a classic understatement. Readers who are familiar with Silverlight, but not so much with WPF are encouraged to dig deeper. And do let us know which of these features you'd like to see in Silverlight.</p> <p>Further content:</p> <ul> <li><a href="http://channel9.msdn.com/Showforum.aspx?forumid=14&tagid=329">Channel 9's ongoing WPF Series</a> has a set of videos where folks from the team talk about features and do demos</li> <li><a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx">Scott Guthrie: VS 2008 and .NET Framework 3.5 SP1</a></li> <li><a href="http://blogs.msdn.com/tims/archive/2008/05/12/introducing-the-third-major-release-of-windows-presentation-foundation.aspx">Tim Sneath: Introducing the third major release of WPF</a></li> <li><a href="http://blogs.msdn.com/greg_schechter/archive/2008/05/12/a-series-on-gpu-based-effects-for-wpf.aspx">Greg Schechter: A series on GPU based effects for WPF</a></li> </ul>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-6810771.post-27533384425474634222008-04-14T15:15:00.000-07:002008-04-14T15:15:54.429-07:00Silverlight 2: Layout and Rendering engines<p>A layout engine which does precise and optimal size or position calculations is critical in any user interface framework for building responsive, interactive and high-performance applications. The term "layout engine" is often interchangeably used with "rendering engine" to mean code that takes markup content along with styles, templates and other formatting instructions to display content on screen. As prominent examples, you know of Trident, the layout engine in Internet Explorer, or Gecko which performs a similar function in Netscape/Mozilla family browsers. </p> <p>In Silverlight, we typically look at the layout and rendering engines as two distinct things rather than one amorphous entity. The former handles the math which dictates how UI elements are sized and positioned on screen, and how they may be constrained or clipped in order to fit into the bounding box. The latter deals with the logic of taking bits representing graphical objects and showing them on screen. Lets do a quick lap around these features. <br /></p> <p><strong>The Silverlight layout engine</strong></p> <p>Among the goals of the layout engine is to:</p> <ul> <li>Enable highly complex and dynamic user interfaces where elements can be automatically positioned</li> <li>Provide a gradient of Panel choices in which to place UI elements, as well a mix of knobs to achieve very precise positioning: absolute/relative sizes, margins, padding, static or specified sizes as well as dynamic or calculated sizes</li> <li>Allow app code to participate in layout. This can be as simple as being notified on layout events, or as niche as extending the layout behavior by actively participating in the process</li> </ul> <p>With the design patterns and public APIs of the layout engine in Silverlight, we've stayed close to the behavior displayed by Windows Presentation Foundation (WPF), even if the implementation is custom keeping in mind the needs and constraints of Silverlight. </p> <p>Very simply put, layout in WPF or Silverlight is a recursive operation that involves two passes, measurement and arrangement. During measurement, a child element is effectively told by its parent element <em>"Here's how much room is available to all you kids and your 'gear'. Tell me how much </em>you<em> really need."</em> Once all appropriate elements in the tree have been measured in this way, the arrangement pass kicks in. At this time, the elements' sizes are finalized. The parent element can choose to say either <em>"Sure you can have your own room"</em> or if the demands are profligate, then <em>"Oh, the kids these days! I'd like champagne on a beer budget too. But no can do. Get your things together - you and your brother are rooming up."</em> After arrangement, the elements in the tree are ready to be rendered. </p> <p>Example of a grid with constrained size. The rectangle within it asks the parent for all its got -- and gets it:  <br /><font face="Courier New" size="1"><Grid Width="250" Height="600"> <br />      <Rectangle Fill="Red" /> <br /></Grid></font></p> <p>Example of a stack panel with constrained size. The first rectangle gets what it desires. The second rectangle gets clipped because it desires more than the parent has room for:</p> <p><font face="Courier New" size="1"><StackPanel Width="<font color="#ff0000">250</font>" Height="600"> <br />      <Rectangle Fill="Red" Width="<font color="#ff0000">250</font>" Height="300"/> <br />      <Rectangle Fill="Green" Width="<font color="#ff0000">300</font>" Height="300" /> <br /></StackPanel></font></p> <p>Needless to say, the layout algorithm employs optimizations to ensure layout doesn't happen until absolutely necessary, and when it does, there selectiveness on which items need to be considered. I won't go into too much detail but primarily this keys off the knowledge that certain properties such as Width, Height, Visibility, Stretch, Alignments, Margins etc. are deemed layout-affecting and a change to one or more of these invalidates the current layout, causing Silverlight to re-layout i.e. measure and arrange its UI elements.</p> <p> </p> <p><strong>The Silverlight rendering engine</strong></p> <p>Silverlight uses vector graphics as its rendering data format, giving its graphics the ability to scale to any size or display resolution.</p> <p>In WPF, the Visual class is the basic abstraction that provides rendering support. UI controls like Button, ListBox etc. derive from UIElement and FrameworkElement, which derive from Visual. In Silverlight we've dispensed of the Visual type, folding its functionality into its child types. This way we can keep the object hierarchy shorter, have one less type to deal with, small size reductions and still be a subset of WPF both conceptually and behaviorally. Silverlight also generally discards the notion of distinct visual and logical trees, effectively reducing to one tree where visual/drawing/logical info is persisted. This tree is the effective consolidation of elements you created in markup or code, containing all rendering info needed to output to screen. The tree determines rendering order as well - starting with the root visual (the top-most node), progressing to its children from left to right. If an element has children, then they are traversed before its siblings.</p> <p>Silverlight uses <a href="http://msdn2.microsoft.com/en-us/library/ms748373.aspx#visual_rendering_behavior">retained mode rendering</a> and employs a custom rendering pipeline, not relying on OS libraries like GDI/GDI+/WPF for better consistency and performance across platforms. It uses occlusion culling among other approaches to prevent <a title="Definition of overdraw in graphics" href="http://www.exaflop.org/glossary/gloss.cgi?graphics.overdraw">overdraw</a>. This is particularly significant if you consider that a typical application has 3-4x overdraw and perhaps 10x if effects are employed. Another very significant (but not commonly known) fact about Silverlight's rendering engine is its <a href="http://en.wikipedia.org/wiki/Multi-core">many-core</a> support; specifically how it was architected to utilize the raw power of multiple cores and subdivide rendering tasks to be processed in parallel by CPU cores as they have available time. This provides phenomenal linear speed increases when you have dual, quad or 8 core machines. In this regard, Silverlight has few peers. Of course, one must not gloss over the detail that other functions such as tree walks, layout, template expansions etc. do not necessarily scale linearly.</p> <p><strong></strong></p> <p><strong>Post-script:</strong></p> <p>Blog posts are never a substitute for <a title="Silverlight 2 Documentation" href="http://msdn2.microsoft.com/en-us/library/bb404700.aspx">good documentation</a> (and we're fortunate to have a <a title="Silverlight SDK Doc Writers' Blog" href="http://blogs.msdn.com/silverlight_sdk/default.aspx">great team of doc writers</a>). My intent with this post was to mix the "how" with the "why". One of my mental models is to view teams based on what I call "team DNA". In this respect, the UI platform team in Silverlight traces its DNA to the User32, GDI/GDI+, Trident, WinForms and WPF teams (Note: I'm way oversimplifying - we have a far more diverse team in ideas, outlooks and heritage than I can describe with words; but bear with me here). I think the team's DNA gives it a rich corpus of experience in blending the web and desktop, plus the ability to distil things on the "what works", "what doesn't work" and "what didn't work then, but will now" buckets. In the spirit of evolution and due to the unique size and platform requirements, the layout and rendering engines as other areas in Silverlight, introduce optimizations and use different algorithms than their WPF cousins. Feedback is always appreciated.</p> <p>Further reading:</p> <ul> <li><a href="http://msdn2.microsoft.com/en-us/library/cc189087(VS.95).aspx">Object positioning and layout in Silverlight 2</a></li> <li><a href="http://msdn2.microsoft.com/en-us/library/ms745058.aspx">The WPF Layout System</a></li> <li><a href="http://msdn2.microsoft.com/en-us/library/ms748373.aspx">Overview of WPF Graphics Rendering</a></li> </ul>Unknownnoreply@blogger.com9