Using Rx (Linq to Events) with WPF

A recent series of blog entries at http://themechanicalbride.blogspot.com/ introduced the Rx framework (System.Reactive.dll) which is an assembly used in the Silverlight toolkit for UI testing purposes.  It essentially provides a mechanism to do event driven programming through LINQ.  I'll refer you to the blog referenced above for all the gory details - frankly I'm still trying to wrap my mind around it! Silverlight isn't my favorite technology however, I much prefer working in … [Read more...]

Playing with WPF Behaviors – a WatermarkText behavior

One of the coolest new features of Blend 3 is the inclusion of behaviors. This new feature formalizes the "attached behavior" model that has become so prevelant in WPF (and Silverlight) development.  I won't go into details on the architecture - instead I'll refer you to a nice reference: http://blogs.msdn.com/expression/archive/2009/05/19/link-round-up-behaviors-related-posts.aspx To play with this new support, I built a WatermarkTextBehavior which places a watermark into a TextBox … [Read more...]

rCAT 1.0 beta is online

A project I've been working on for the last two months is finally online in beta form - check out http://rcat.codeplex.com/ It's essentially a biological alignment viewer for RNA sequences.  Here's a couple of screen shots: Alignment Viewer 2D Structure Viewer 2D Circle relationship Viewer You can download the source code from the above link to play with it - it's a MVVM implementation and has quite a bit of interesting optimizations in it for performance purposes, including a read-only … [Read more...]

Menus and MVVM (2)

In the previous post, I wrote about using the MVVM pattern with Context Menus, but you can use it with top-level menus too -- for example, perhaps I'd like to manage a set of options through a set of checkboxes.  First, let's start with my list of options - for simplicity, we'll just make it an enumeration: public enum Test{   A,   B,   C,   D,   E,   F} Next, let's define a ViewModel to wrap this - each entry should support a … [Read more...]

Using MVVM with Menus in WPF

One question I've fielded a couple of times is how to manage menus, primarily context menus, with the MVVM pattern.  It turns out to be pretty easy once you know the "trick".  The key thing to keep in mind is that menus are just ItemsControls - they support data templating and binding like any other ItemsControl.  However, the part where people get lost is in hooking up the commands.  Here's the trick: Step 1: Define some code behind construct to manage each menu item in a … [Read more...]

WPF MVVM Helper Library (WPF + MVVM = testability)

There's been a lot of talk about the Model-View-ViewModel pattern recently and it's usage around the WPF and Silverlight technology stack.  When teaching WPF, I always introduce students to MVVM as part of the Essential WPF class, it's an incredibly useful pattern that really separates the UI from the code behind behavior.  One of the things I give the students is a library to do MVVM - I also use it in my consulting work.  With all the focus on it lately, I figured maybe it's … [Read more...]

Adding to an ObservableCollection from a background thread

One annoying thing about ObservableCollection<T> is that it doesn't support modifications from background threads.  That is to say, the CollectionChanged notification doesn't marshal to the proper thread when it is raised and it causes the exception "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread".  I ran into this problem a while back and searched out to see if someone else had solved it. I … [Read more...]

It’s been such a long time.. [WPF + Windows 7]

Update Microsoft has released the API code pack including Windows 7 support -- get it here: http://code.msdn.microsoft.com/WindowsAPICodePack Well, it's been a while since I posted anything, I'm sorry! I've been busy working with Windows 7 and Microsoft Surface touch-computing. To that end, I needed to get access to some of the new Windows 7 APIs in managed code ... which isn't supported yet (but is coming). So I built an interop library to access: Scenic Ribbon (native Win32 … [Read more...]

Debugging WPF with VS2010

One of the coolest new debugging features included with VS2010 CTP1 is the management of WPF event traces directly in the IDE.  With this feature you can turn specific event traces on and off and have them show up in the debug window.  The default setting is to just show data binding errors - the existing behavior.  But now you can view resource lookups, routed event creation, etc. Here's the dialog: … [Read more...]

Outlined Text in WPF

One thing that's kind of cool in WPF is that you can use brushes to fill almost anything and that there are some really cool brushes in the toolkit.  It always blows people away when you show them a piece of text filled with a live video complements of a Visual Brush.   But, unfortunately text doesn't have a stroke property - only a fill so you can't add an edge to it.  You can layer another piece of text under it, but often it doesn't quite match up size-wise when you do … [Read more...]