My blog has moved!

Visit http://blog.adamroderick.com/ and update your bookmarks.

Thursday, September 2, 2010

Slides from ASP.NET MVC Presentation

Thanks to everyone who came to the Robert Half event, where I presented on the MVC framework. 

Download the slides, or if you want, download the sample code from the presentation.

Let me know if you want to discuss further any of the info from the event!

Thursday, July 15, 2010

Download to Excel Behavior for Silverlight DataGrid

I wrote a behavior to export a DataGrid to Excel.  Silverlight allows saving files, and this behavior transforms a DataGrid into a .csv file.

To use, add a reference to your project to the assembly, and you will see the DownloadToExcel behavior under the Assets tab:

assets

Add the behavior to any UIElement.  In this case, I added it to a button:

addedBehavior

The default event selected on the button is the Click event, which is what we want.  Set the Target Object by clicking on the little target icon and then choosing the data grid you want to export to excel:

chooseTarget

Below is a screenshot of the test app.  When we run it and click the button, we are prompted to save the file.  This is the DataGrid in the sample code:

datagrid

The resulting .CSV file--which opens in Excel by default--it looks like this:

excel

 

Download just the .DLL or the source code with sample app.

Thanks to stackoverflow and those who responded to this question for giving me insight.

Labels: ,

Tuesday, July 13, 2010

Viewing WCF Binary-encoded messages in Fiddler

RIA Services (because it is based on WCF) binary encodes the messages it sends across.  These are a pain to try and read when using Fiddler. 

MSDN has a plugin for Fiddler that decodes the message and displays the decoded XML:

FileDownload[1]

Super simple to use, just download and drop the DLL in the Inspectors folder of the Fiddler installation folder.  Details here, and download directly here.

Labels: ,

Friday, July 9, 2010

Extension Method to Populate an ObservableCollection

I have been building a business application using the model-view-viewmodel pattern and RIA Services in Silverlight 4.  Typically, a viewmodel class will make a call to one of the services to get some information.  If this information is a collection to be displayed, I will populate an ObservableCollection property with the collection of items. 

When Silverlight first loads the control, the UI bindings subscribe to the property changed events that the ObservableCollection property fires anytime items are added or removed from the collection.  If I populate my ObservableCollection property like the following, it is a new object on the heap, and the UI binding is not subscribed to anything on the new object:

this.ObservableCollectionProperty = new ObservableCollection(collectionReturnedFromService);

To make things work the way I wanted, I had to call Clear on the existing ObservableCollection and then add each item.  This was common enough that it merited an extension method:

Labels:

Saturday, April 3, 2010

Streamgraph in Silverlight

(Here is the link to the CodePlex project: http://streamgraph.codeplex.com/)

I was very impressed with the work done by Lee Byron and Martin Wattenberg on their streamgraphs.  They did their work in processing, which is a nice tool for creating math-based data visualizations. 

A few days ago, I started working on a reusable streamgraph component in Silverlight, and I was running into the same challenges I was sure Lee and Martin had already overcome.  Only 24 hours after I started, they released their processing source code.  Thanks to that, I was quickly able to port it over to Silverlight.  It is currently very code heavy and does not yet make use of some of the features it could, but it functions. 

For next steps, I would like to utilize some of the features of Silverlight.  Suggestions welcome!

  • Visual states to add interactivity
  • DataTemplates to make the rendering simpler
  • Data binding to make the calculations simpler and add interactivity
  • Animations to add interactivity
  • Put it all in a class library and turn it into a reusable component

What else would make this thing rock?

Here are some snapshots of my journey:

After some intense java-to-Silverlight translating, this is the first thing that actually rendered.  I entertained thoughts of giving up.

firstpass

 

I worked through some of the scaling problems and realized I was pretty close to the real deal.

secondpass

 

Not looking too bad!

thirdpass

 

Next step was to create a predictable data source to give me something easy to experiment with.  So, boring but predictable:

trying to create a predictable data source

more fun with predictable sample data source

 

Next step was to get the color palette working.  The palette I am using is the one used by Lee and Martin in their NYT data viz.  The larger the surface area of a segment, the darker it should be.  I lowered the number of segments to 5 and then added my own sixth, smaller segment to show that the palette colors the segments appropriately:

lastpass

 

You can see below there is one large middle segment that is dark.  For the other segments, the later a segment begins, the smaller its overall surface area and the lighter its color is. 

color palette working

Check out the CodePlex page http://streamgraph.codeplex.com/ to see how it works.

Labels: ,

Friday, February 26, 2010

Adding Clipping to a Canvas

I’m going through Jianqiang’s series laying out Silverlight’s potential as a game-building platform, which I am pretty excited about.  Expression Studio—and Visual Studio—are way more intuitive than I remember a lot of the Flash tools being.  My small contribution to the first post is to add clipping to the canvas.  If we are going to be building a game, and if the canvas is the frame where the user interaction happens, then the objects should be contained in the canvas.  In the two shots below you see the before and after of the animation—the red block just moves to wherever you click the mouse:

 

1   2

 

The animation works fine—the problem is the red block spills out beyond the boundaries of the canvas.  This is the default behavior of Canvas, but is easy to change with clipping.  The following XAML, placed inside the Canvas XAML, hides objects as they move outside the clipping region:

<Canvas.Clip>
    <RectangleGeometry Rect="0,0 800,600" />
</Canvas.Clip>

Notice the Rectangle geometry is sized to the same size as the canvas.  The result is the appearance the the objects are actually “inside” the canvas:

 

1   3

Labels:

Monday, February 22, 2010

Slides from Presentation on SharePoint Social Features 2/18/2010

I gave a presentation to the Colorado SharePoint Users Group on Thursday 2/18/2010.  It was a run through of all the social networking and social content generation features of SharePoint Server 2010.  I then walked through how to use the profiles object model to programmatically access some of the features and data, and render the result in a Silverlight web part.

Here is a link to the video.

Here is a link to the slides—not much to them, though, most of the content was in the demo.

Labels: ,