Detecting UI Thread Misuse

One of the challenges in building a UI application is correctly using the UI thread.  This is a shared resource, and so any misuse has the potential to have global application effect. The most common form of misuse is using the UI thread for a long period of time.  In severe cases this causes the…

1

WPF ICommandSource Implementations Leak Memory!

Actually the title of this article should be entitled “How to use WeakEventManager with ICommand implementations”, but the memory leak title is more exciting (and true) Overview Some WPF controls, such as Buttons, are command sources.  A command source has 3 properties, Command, CommandParameter and CommandTarget.  When the control does it’s action (like Click for…

3

Creating Attached Properties And Services

One cool thing about DependencyProperties is the ability to have AttachedDependencyProperties (or Attached Property for short).  Regular properties are defined on a type and exist for instances of that type and sub-classes.  An Attached Property is defined in one type, but can be applied to any instance of DependencyObject. So how does this work?  Well…

1

Performing Bulk Modifications To a Databound Collection

On a WinForms project in the past we were working on scalability and performance.  One of the things we discovered was that individually invoking items to the UI thread was a bottleneck. The theory is that the each time one does a BeginInvoke it adds a message to the Message queue.  This adds overhead.  If…

1

AddRange and ObservableCollection

The Issue Recently a friend asked a question about ObservableCollection.  The question was how to do an “AddRange” method on it. The obvious answer is, of course, just write a method which iterates over the input collection and calls Add for each.  But this really isn’t the answer, because the question really isn’t about AddRange…

3

Developing Reusable Controls with the Model-View-ViewModel Pattern

There have been several great blogs and articles about the Model-View-ViewModel pattern lately.  I thought I would share my own example and thoughts on it – specifically on using this pattern to develop reusable controls. Rather than re-explain what the Model-View-ViewModel pattern is I suggest you read these other articles.  I recommend ·        http://msdn.microsoft.com/en-us/magazine/dd419663.aspx ·       …

1

Mouse vs Keyboard and ContextMenus

Recently I was asked to modify one of my controls so the user of the control could get the proper placement of thier context menus.  My intial response was for them to use the placement properties on the ContextMenu/ContextMenuService to achieve the right positioning. Then the real issue came out.  They wanted different positioning based…

2

Creating Adorner content in XAML

I’ve been working on a problem of having a “popup” control in my project.  For various reasons the Popup class isn’t working for this scenario, because the scenario is outside the designed scope of Popup. So I’ve been looking at the AdornerLayer as a way to get a popup effect.  One of the things I…

5

ConvertingReadOnlyObservableCollection

In my project we always deal with live data – that is data from the Data Model may change at any minute due to reasons like user interaction or an asynchronous change in what system the UI is modeling. For the most part we want the UI to update automatically in response to the changes. …

1