Detecting Memory Leaks in WPF

Monday, November 15, 2010 6:15:28 PM (GMT Standard Time, UTC+00:00)

This post is related to helping someone on the MSDN forum to try to find a memory leak in their application.  Others may find the technique useful for detecting memory leaks.

Here is the forum thread:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/268462f3-ec45-4507-996e-70fb1f00d68f

Generic Recursion using IEnumerable

Thursday, September 16, 2010 6:11:25 PM (GMT Daylight Time, UTC+01:00)

This is a handy little LINQ extension I use all of the time to recurse through IEnumerable<T> object graphs. 

/// <summary>
/// Traverses the specified source.
///  
///var total =
///    Application.Current.Resources.MergedDictionaries.Recurse<ResourceDictionary>(
///        obj => obj.MergedDictionaries);
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source">Root object.</param>
/// <param name="fnRecurse">The function used in recursion</param>
/// <returns></returns>
public static IEnumerable<T> Recurse<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> fnRecurse)
{
    foreach (T item in source)
    {
        yield return item;

        IEnumerable<T> seqRecurse = fnRecurse(item);

        if (seqRecurse != null)
        {
            foreach (T itemRecurse in Recurse(seqRecurse, fnRecurse))
            {
                yield return itemRecurse;
            }
        }
    }
}

Twin Cities Code Camp – April 2010

Thursday, March 11, 2010 3:03:42 AM (GMT Standard Time, UTC+00:00)

Jason Bock just posted the sessions for TCCC8.  Looks like some interesting material… looks like there is going to be content on developing for Win Mo 7.

WPF Toolkit 2010 Released

Thursday, February 25, 2010 1:52:53 AM (GMT Standard Time, UTC+00:00)

I stumbled across this looking for for WPF samples.  It looks like they updated the WPF Toolkit.

http://wpf.codeplex.com/releases/view/40535

PDC 2009 Recap PodCast

Wednesday, January 27, 2010 8:54:34 PM (GMT Standard Time, UTC+00:00)

You can hear about some thoughts on PDC 2009 over on Microsoft Developer Evangelist Jeff Brand’s blog.  He sat down with Rocky Lhotka, Scott Davis and myself in December and we talked about our thoughts on PDC.

http://www.slickthought.net/post/2010/01/07/Spaghetti-Code-Recaps-PDC-2009.aspx

Building Loosely Coupled Applications – V2

Wednesday, January 27, 2010 8:29:58 PM (GMT Standard Time, UTC+00:00)

I gave this presentation in St. Louis and Minneapolis last year.  I updated it and gave it to the .NET User Group in Mankato, MN last night.  It now includes a section on MEF (Managed Extensions Framework).

You can download the updated deck and slides below.

Code and Deck

What’s new in Silverlight 4

Wednesday, January 27, 2010 8:20:07 PM (GMT Standard Time, UTC+00:00)

Below is the presentation that I gave to the Twin City Silverlight Users Group last month.  I had issues with my laptop that I got from PDC… which also happened to be the laptop that I used for the presentation so it took me a while to recover the files.  Attached is the presentation.

ListView with AutoColumns

Monday, December 07, 2009 10:00:10 PM (GMT Standard Time, UTC+00:00)

When you are prototyping it is nice to get things up and running quickly.  The other day I was using the DataGrid to prototype some work I am doing and it just so happened the result sets were rather large.  I like the fact that the DataGrid can dynamically create columns on the fly… but with large working sets of data, it takes longer to render then a GridView.

With that, I created a simple mechanism that will auto generate the GridView for you through reflection. Set the returning GridView to the View property on the ListView. Here are the helper calls:

public class GridViewHelper
   {
       /// <summary>
       /// Auto generates a GridView based on public properties in an object.
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <returns></returns>
       public static GridView AutoGridView<T>()
       {
           GridView view = new GridView();
 
           foreach (PropertyInfo info in typeof(T).GetProperties())
           {
               GridViewColumn gridViewColumn = GenerateGridViewColumn(info.Name);
               view.Columns.Add(gridViewColumn);
           }
 
           return view;
       }
 
       /// <summary>
       /// Auto generates a GridView based on public properties in an instance of an object.
       /// </summary>
       /// <param name="instance">The instance.</param>
       /// <returns></returns>
       public static GridView AutoGridView(object instance)
       {
           GridView view = new GridView();
 
           foreach (PropertyInfo info in instance.GetType().GetProperties())
           {
               GridViewColumn gridViewColumn = GenerateGridViewColumn(info.Name);
               view.Columns.Add(gridViewColumn);
           }
 
           return view;
       }
 
       /// <summary>
       /// Generates the grid view column based on a property name
       /// </summary>
       /// <param name="propName">Name of the prop.</param>
       /// <returns></returns>
       private static GridViewColumn GenerateGridViewColumn(string propName)
       {
           GridViewColumn gridViewColumn = new GridViewColumn();
           gridViewColumn.Header = propName;
           gridViewColumn.DisplayMemberBinding = new Binding(propName);
           return gridViewColumn;
       }
 
       /// <summary>
       /// Define the Property Names you want to show in the Grid.
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="columns">The columns.</param>
       /// <returns></returns>
       public static GridView AutoGridView(params string[] columns)
       {
           GridView view = new GridView();
 
           foreach (string propName in columns)
           {
               GridViewColumn gridViewColumn = GenerateGridViewColumn(propName);
               view.Columns.Add(gridViewColumn);
           }
 
           return view;
       }
   }

Microsoft Application Architecture Guide – Second Edition available for download.

Tuesday, December 01, 2009 2:09:34 AM (GMT Standard Time, UTC+00:00)

Ran across this today looking for some other things on DotNet.

http://blogs.msdn.com/microsoft_press/archive/2009/11/22/new-book-microsoft-application-architecture-guide-second-edition.aspx

WPF Instigator Code Released on CodePlex

Friday, November 06, 2009 10:57:08 PM (GMT Standard Time, UTC+00:00)

You can get the source code to Instigator at:

http://instigator.codeplex.com/