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:

http://www.codeproject.com/KB/WPF/AttachedBehaviors.aspx

Enjoy!

About these ads

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?

    Thanks!

  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

Follow

Get every new post delivered to your Inbox.

Join 285 other followers

%d bloggers like this: