Properties with property changed event, part 3

A while ago, I talked about how to write basic events for changed properties, and about the INotifyPropertyChanged interface. There is a third way to manage events, which is especially useful when your class has many events, but you expect a very low number of them to be actually handled.

As discussed before, every EventHandler stored in your object takes up space, which is a bit of a waste if most of those will be null. But events allow you to implement the add and remove methods yourself, so you can choose where to store the EventHandler delegate.

One way to do that is through the System.ComponentModel.EventHandlerList class. System.ComponentModel.Component exposes an Events property of this type, which is used by all classes inheriting from Component, including all Windows Forms controls.

See my U2U blog for a complete example, featuring a CueBannerTextBox (like the Internet Explorer 7 search box) with a CueBanner property and a CueBannerChanged event.

Technorati Tags: , , , , ,

Sending the LINQ To SQL log to the debugger output window

I was playing with LINQ To SQL (again) this evening, and I thought: why can’t I see the generated SQL statments in my debugger output window?

The DataContext.Log property is a great help to learn writing LINQ To SQL queries. All you need to do is assign a TextWriter to it, and you get to see al the SQL statements generated by the data context. But where do you send them to? Console.Out is an option, but you probably don’t want that in a release build. Furthermore, it doesn’t quite work for Windows services or ASP.NET applications. That’s why I wrote DebuggerWriter, an implementation of TextWriter that writes to the debugger log.

Find the code at my U2U Blog.

Compiling Regular Expressions

Update your bookmarks, new posts on .NET related stuff will be posted to The first new one to appear there is all about compiling regular expressions in .NET, with a free compiler tool to download. Enjoy reading.

WPF/E preview and new Expression designers released

Microsoft released the first CTP for WPF/E, short for Windows Presentation Foundation/Everywhere, a WPF subset to run in browsers (Firefox and IE on Windows, Firefox and Safari on the Mac). Broadly available for customers in the first half of 2007, “WPF/E” experiences will require a lightweight browser plug-in made freely available by Microsoft.

Just in case you haven’t figured out yet who they are competing against, Michael Swanson released a free Macromedia Flash to WPF/E converter

Also this week, Microsoft released Expression Blend Beta 1 (formerly known as Expression Interactive Designer, a graphical WPF XAML editor) and Expression Design December 2006 CTP (formerly known as Expression Graphic Designer).

Expression Blend looks good, though the first thing I did was change the default dark theme to the light theme, and decrease the workspace zoom to 90%. I need a bigger screen…

Paint.NET V3 Beta 1 available

Rick released the first beta for Paint.NET V3. This version is now feature complete, and all known bugs have been fixed. The coolest new feature in this release is a Perlin noise based clouds renderer, with – as usual – a very easy to use configuration panel.

I’d say it’s about time you uninstall that cracked Photoshop!

Linq to XSD preview released

Last Monday, the Microsoft XML Team released the first Linq to XSD preview.

While the LINQ to XML programmer operates on generic XML trees, the LINQ to XSD programmer operates on typed XML trees — instances of .NET types that model the XML types of a specific XML schema (XSD). […] LINQ to XSD is integrated into Visual Studio; so you just tag an XML schema as [a] ‘LINQ to XSD schema’, build your project, and the automatically derived object model is then part of your solution — just as if XML schemas were .NET types.

I only had a quick look, but I have to say it looks very promissing! Send them your feedback, but hurry, I want this to be included in Visual Studio Orcas.

Creating a Data Access Layer with Linq to SQL, part 2

Last time, we looked at how Linq To SQL might impact how we think about what a Data Access Layer (DAL) is, based on the dependencies between assemblies. This time, we’ll take a different approach: let’s look at typical Linq to SQL code, and try to decide where to put it. I’ll use a code sample from the “DLinq Overview for CSharp Developers” document included in the Linq May CTP (in C# 3.0, but the same applies to VB9).

Continue reading ‘Creating a Data Access Layer with Linq to SQL, part 2’

Amazing XAML

Since the .NET Framework 3.0 has been released, the interest is Windows Presentation Foundation (WPF) and XAML is growing. A good understanding of XAML and how it works is essential to understand WPF. A while back, Peter Himschoot wrote an excellent article about it: Amazing XAML.

Getting started with Windows Presentation Foundation (WPF)

Josh Smith compiled a list of links to WPF resources to help you get started. Oddly enough, he didn’t mention Microsoft’s Expression Interactive Designer, you might want to take a look at that as well. Thanks for the list Josh.

Creating a Data Access Layer with Linq to SQL, part 1

There is no doubt that Linq to SQL will have an enormous impact on the way we write data access layers. I wouldn’t be surprised to find out that the impact is so profound, that we might even have to reconsider the very nature of a data access layer. In fact, what is a data access layer (DAL) anyway?

Continue reading ‘Creating a Data Access Layer with Linq to SQL, part 1’