Introduction to attached behaviors

I just published an article on CodeProject that introduces the popular technique of attached behaviors in WPF.  The demo app is an extension of the demo provided by my ‘Simplifying the WPF TreeView by Using the ViewModel Pattern‘ article.  The new article shows how you can attach a behavior to TreeViewItem so that it scrolls into view upon being selected by a ViewModel object.  If you’re interested, here’s the link:



4 Responses to Introduction to attached behaviors

  1. […] I recommend you to have a look at Josh’s article about attached behavior. Josh wrote an article about a very nice way to solve a problem that would […]

  2. Quang, Tran Minh says:

    Hi Josh,
    I tried your technique in the exact the same way for ListViewItem but somehow it didn’t work. I have a ListView that is data bound to a collection and its SelectedItem is bound to an ActiveXYZ in the ViewModel. When I set the ActiveXYZ, the seletected ListViewItem is not brought to view as expected.

    Is there any good explanation for that?


  3. Quang, Tran Minh says:

    Hi Josh,
    I found the solution. We have to call ListView.ScrollIntoView(object…) instead!
    So I wrote a ListViewBehavior class that implements the behavior for a ListView instead of ListViewItemBehavior

  4. Josh Smith says:

    Nice find, Quang!

%d bloggers like this: