Archive for ‘Dev’

May 14th, 2012

Clipping Path nuance in WPF/Silverlight/WP7

When you’re working with clipping paths in WPF and/or Silverlight there is a little nuance that you need to know about. If the alignment of your path and the item your are masking are different you’ll get some pretty bizarre behavior. The item your masking will appear in the correct position, but the clipping path will appear offset.

The default orientation of a path is “Stretch” – this is not what you want in most cases.

Make sure that the alignment of both your Image (in this case) and your Path are set to ‘Left” and “Top”, otherwise your clipping mask will be offset.

This one stumped me for a while, so hopefully this saves someone else time.






You can quickly apply your clipping path to the item by selecting both the path and the item and then right clicking -> roll over PATH -> and select Make Clipping Path.

November 11th, 2010

My guest chapter for Hacking Silverlight: Community Edition

Hacking Silverlight: Community Edition CoverI’ve been working hard to stay involved in the local user group community. My adventures put me in touch with a local Silverlight MVP, David J. Kelley. David has been working on a number of projects, one of which is a follow-up book to his first title Hacking Silverlight. This new edition is titled Hacking Silverlight: Community Edition. David asked me to write a chapter that highlights some of the great projects that are on My chapter is titled Codeplex Projects Everyone Should Know About and you can read it here.

In addition to the book there is a great Code Browser that you can install which will guide you through learning the XAML/C# techniques highlighted in the book. It was a great learning experience and I hope to be able to contribute more in the future.

July 14th, 2010

Using HtmlAgilityPack to parse a website. Twitter Bird Image ResultsIn my line of work I’m often asked to come up with some unique data sources to power some of our information visualizations. Often times this data  is not available in an API or RSS feed. Sometimes it’s just available in HTML. Up until recently I’ve shied away from parsing HTML with RegEx or XML parsers because they can be really processor intensive and give mixed results.

This past week I had another need for some data in an HTML page as a data source, this time for a WPF application. Since I needed to make it work I did a quick search on on the internet for some HTML parsers. What I found was amazingly useful. The HtmlAgilityPack is a .NET library that gives all the tools to parse your HTML, retrieve the data you’re looking for. It supports Linq to Objects and has XPATH implementation to let you find what you need easily. PLUS, because it’s on codeplex it’s open-source and free! Fantastic!

Here is a little code snippet if you ever wanted to know how many Twitter Bird image results are in a search. Note that I’m using the XPATH syntax to find the <span> tag with and ID value of ‘sw_ptc’ and then select the InnerText from that node. HtmlAgilityPack has lots of XPATH and XSLT options so you’ll be able to find whatever your looking for with minimal effort.

using System;
using System.IO;
using System.Net;
using System.Configuration;
using System.Xml.Linq;
using HtmlAgilityPack;
class BingCounter
        private WebClient webClient;
        public BingCounter()
            Uri _feedUri = new Uri("");
            webClient = new WebClient();
            webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(stringDataCompletedEvent);
        private void stringDataCompletedEvent(object sender, DownloadDataCompletedEventArgs e)
            if (e.Error == null)
                    byte[] xmlString = e.Result;
                    HtmlDocument doc = new HtmlDocument();
                    doc.Load(new StreamReader(new MemoryStream(xmlString)));
                    string results = "";
                    foreach (HtmlNode span in doc.DocumentNode.SelectNodes("//span[@id='sw_ptc']"))
                        results = span.InnerText;
                catch (Exception exp)


Have fun and happy coding.