Silverlight

Source code for Jason Dolinger’s Model-View-ViewModel presentation

December 3rd, 2008

Some time back, I posted Jason’s presentation on Model-View-ViewModel and dependency injection with WPF and Unity (if you haven’t checked it out yet, you really should… the stuff there is good for Silverlight, too).  There were numerous requests to take a look at the source code.  It’s now available here.

Shawn Burke – Silverlight and WPF Control Development

October 5th, 2008 / Development in a Blink

Control Freak.

New Silverlight controls

  • DockPanel
  • WrapPanel
  • ViewBox
  • Label
  • HeaderedContentControl
  • Expander
  • TreeView
  • NumericUpDown
  • AutoComplete
  • Accordion

Details

  • Expected to be previewed at the PDC
  • Controls will use the Visual State Manager
  • Source code up on CodePlex including
    • Unit test
    • Updated test harness
    • OSI-Approved MS-PL license

Shawn has additional details on release frequency and team members.

Silverlight 2.0 FireStarter – NYC September 13

August 28th, 2008 / Development in a Blink

Microsoft is offering a free full day dive into Silverlight.

Register Here

More details HERE and agenda to follow.

Debugging Silverlight with Windbg and SOS

August 25th, 2008 / Development in a Blink

If you have hangs, performance, memory issues, exceptions or crashes in Silverlight applications you can debug them using windbg and sos just like you would if the issues occurred in other .net applications.

http://blogs.msdn.com/tess/archive/2008/08/21/debugging-silverlight-applications-with-windbg-and-sos-dll.aspx

Maybe this works with Automated Debugging using WinDbg and PowerShell.

Silverlight threw an exception

August 18th, 2008 / Development in a Blink

This was in the stack trace.

at MS.Internal.JoltHelper.FireEvent

Jolt was the code name of Silverlight.

Prototyping desktop controls that use the Visual State Manager

August 8th, 2008 / Development in a Blink

John Gossman blogs on the VisualStateManager for desktop WPF which was delivered initially in Silverlight.

Silverlight - Parts & States Model with VisualStateManager

June 23rd, 2008 / Development in a Blink

Karen Corby is doing a multi-part write up on managing states and transitions inside of controls.

Silverlight 2 Beta 2 TabControl

June 10th, 2008 / Development in a Blink

After asking the oracle of infinite knowledge (Google) for examples on Silverlight Beta TabControl, I came up with nothing.

Attempting to Close the Discoverability Gap I changed my search to WPF TabControl. Starting with this example I came up with this working Silverlight TabControl.

image 

Xaml

  <c:TabControl TabStripPlacement="Left">
   <c:TabItem >
    <c:TabItem.Header>
     <StackPanel Orientation="Horizontal">
      <Ellipse Width="10" Height="10" Fill="Green"/>
      <TextBlock Text="Toolbox" Margin="5"/>
     </StackPanel>
    </c:TabItem.Header>
   </c:TabItem>
   <c:TabItem >
    <c:TabItem.Header>
     <StackPanel Orientation="Horizontal">
      <Ellipse Width="10" Height="10" Fill="DarkGray"/>
      <TextBlock Text="Server" Margin="5"/>
     </StackPanel>
    </c:TabItem.Header>
   </c:TabItem>
   <c:TabItem>
    <c:TabItem.Header>
     <StackPanel Orientation="Horizontal">
      <Ellipse Width="10" Height="10" Fill="DarkGray"/>
      <TextBlock Text="General" Margin="5"/>
     </StackPanel>
    </c:TabItem.Header>
   </c:TabItem>
  </c:TabControl>
 </Grid>

More Silverlight 2 VSM Tutorials

June 9th, 2008 / Development in a Blink

image

Over on Nibbles Tutorials.

VSM Video – Visual State Manager in Silverlight

June 3rd, 2008 / Development in a Blink

HERE.

VSM is currently available as part of Silverlight 2, but we will also support it in the desktop WPF. A preview version of VSM for WPF will be available as a separate download.

Creating Control Skins with Visual State Manager - An Introduction

Microsoft linking Silverlight, Ruby on Rails

June 3rd, 2008

From here:

Microsoft Corp. plans to demonstrate integration Friday between its new Silverlight browser plug-in technology for rich Internet applications and the Ruby on Rails Web framework.

How to more then solve SilverLight DataGrid issue with anonymous types

May 28th, 2008

If you worked with SilverLight’s DataGrid and LINQ you likely noticed that you cannot select anonymous types in your queries. The application simply freezes. That sucks!

You can find some short term workarounds using LINQ to XML.

However, there is another approach. Microsoft has a small library called DynamicLINQ, which you can read about at http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

You can download the solution and add Dynamic.cs to your SL project. It will not compile right away complaining about ReaderWriterLock not being available in SilverLight. I just commented those lines out for now. Here is a code snippet that creates a query on a generic list and returns a collection of dynamic data classes.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq.Dynamic;

namespace SilverlightApplication1
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            List<Data> list = new List<Data>() { new Data() { Age = 5, Name = “Vasya”}};
            var query = list.AsQueryable().Select(”new(Name as FirstName, Age, \”Male\” as Sex)”);
            grid.ItemsSource = query;
        }
    }

    public class Data
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
}

So, with this, in addition to what anonymous types let you do, you can also make your projections dynamic.

SilverLight tests + PowerShell = Automated tests in MSBuild

May 26th, 2008

In this post I will only discuss the way to configure SilverLight unit tests to run completely automated from MSBuild, so that it can also be used as part of continuous integration setup.

SilverLight tests must run within an actual SilverLight plugin rather then .NET Framework. Fortunately, Microsoft provided a test framework and source code for the both SilverLight controls and unit tests.

It is great to get support for TDD for such a new technology as SilverLight 2.0 right from the start. However, it is not possible to run SL tests from MSBuild out of the box. But do not panic, there is an easy solution to thid using PowerShell. PowerShell allows you to use COM objects and fortunately IE comes with a COM API that we can take advantage of. Below is a PowerShell script that creates and redirects IE browser to the SL test page, re-formats the test result output and saves it as an html file. It also returns an exit code > 0 in case of test failures.

param($testURL, $outFile=”TestReport.html”, $visible=$true)

#Instanciate IE, set Visible mode (tests that interact with desktop will require $true to pass
#then navigate to the test page
$ie = new-object -com “InternetExplorer.Application” 
$ie.Visible = $visible 
$ie.Navigate($testURL)  

#poll the content until test execution is complete.
#Note: using $ie.Busy won’t work, because it does not detect that SL application is still running.
#Furthermore, the SL application is running until you close the browser, even after all the tests complete
while (!($ie.Document.body.innerHTML -match “\[ Close \]”))
{
[System.Threading.Thread]::Sleep(100)
}

#Once the execution is complete, we can check the results
#and, thanks to artist rendition by D. Finke, display some shining colors!
$failure = $ie.Document.title -match “(\d*) failures”
if($failure) {Write-Host -NoNewline -ForegroundColor “red” “Failed $matches[1]”}
else {Write-Host -NoNewline -ForegroundColor “green” “Pass   “}

#Heavy RegEx stuff to reformat the body HTML.
#The test results in the SL test framework are displayed  as a narrow column on the right with some
#error messages wrapped into context pop-up or limited in width.
$regOpt = [System.Text.RegularExpressions.RegexOptions]
[regex]::Replace($ie.Document.body.innerHTML, ‘^.*<DIV style=”RIGHT.*?</DIV></DIV>’, “”, $regOpt::Singleline) -ireplace “width: 324px”, “” -ireplace ‘<SPAN title=\”(.*?)\”.*?\(Mouse over for assert trace\)</SPAN>’, ‘$1′ -ireplace ‘</DIV>\w*$’, “” > “$outFile”

#return error code in case of failure so that MSBuild and other tools can detect it. 
Write-Host $testUrl
$ie.Quit()
if ($failure) { exit 1 }

Now, after we have out PowerShell script we can call it from MSBuild and have a completely automated SL unit test setup.
Note: If you will be running it from a service, i.e. TeamCity build agent, you should enable the service to interact with desktop.

Below is a snippet from MSBuild configuration file that calls the SL unit tests via PowerShell. Also, you will need to set PowerShell execution policy to allow the script to run using Set-ExecutionPolicy cmdlet. Check google for available policies.

<Target Name=”RunUnitTests”>  
  
  <Exec IgnoreExitCode=”True” Command=’Powershell .\GetSLTestReport.ps1 “[Your Location]\TestPage.html” ControlTestResults.html’>
   <Output TaskParameter=”ExitCode” PropertyName=”ControlTestExitCode”/>
  </Exec>

  <Error Condition=”$(ControlTestExitCode) > ‘0′” Text=”SL Unit Tests run failed with code $(ControlTestExitCode)”/>
  </Target>

Note: I am using IgnoreExitCode option to allow other tests/tasks to run in case ControlTestResults.html fails. If you do not need this, you can remove IgnoreExitCode and  <Error> tag.
=>

<Target Name=”RunUnitTests”>  
  
  <Exec IgnoreExitCode=”True” Command=’Powershell .\GetSLTestReport.ps1 “[Your Location]\TestPage.html” ControlTestResults.html’ />
  </Target>

Silverlight Interop with client script

May 23rd, 2008

DeepZoom is cool

May 11th, 2008 / Development in a Blink

Radio 1’s Big Weekend http://bigweekend.external.bbc.co.uk/

image

Smartest Silverlight 2 Demo yet

May 8th, 2008 / Development in a Blink

According to Tim Sneath.

Patient Journey Demonstrator

  image  
image   image 

Silverlight Reading

April 6th, 2008 / Tales from a Trading Desk

CRUD operations Silverlight 2 Map / DataGrid Demo DIGG Unit Testing Demystifying URI references for app resources Off topic: Hats off to ThoughtWorks and Anthology

Silverlight Charts: Visifire

April 1st, 2008 / Tales from a Trading Desk

Visifire are offering a collection of charts powered by Silverlight. Hopefully they’ll add some financial specific charts in the future - Bollinger Band, RSI etc

Silverlight 2 Video Tutorials with Jesse Liberty

March 28th, 2008 / Development in a Blink

There are 3 available HERE

I watched the first one “Using the Silverlight 2 Canvas”.

Highlights

  • This version is a read-only view of the Xaml in the designer
  • Grouping radio buttons with a canvas and using GroupName
  • Nesting element types
  • Inheriting left, top and color from the parent element

It’s a great Silverlight 2 tutorial.

Composing a screen layout from Xaml up is an interesting experience. Once you get the hang of it feels much faster than the drag, drop and setting of properties in the property grid.

The next tutorial use the Grid and Stack Panel.

New Silverlight 2 books coming

March 25th, 2008 / Development in a Blink

  Introducing Silverlight Silverlight, coming out of the closet