Monthly Archives: February 2012

WPF TabControl + Mvvm datatemplate binding = Attached properties are lost


At the moment, I’m trying to create some kind of chat with WPF following mvvm pattern so that I can learn and have fun at the same time. Must admit I’m a total beginner in WPF and decided to learn from Josh Smith’s very interesting and teaching article and get inspired  by his workspaces model. Just like his demo, I needed tabs displaying the same view but with different datacontexts of course since one tab would be dedicated to one conversation (we don’t want to intermingle recipients !). I really admired the elegant and simple way of applying a view to a viewmodel, no code behind, everything centralized in a uncoupled resources dictionary :

<DataTemplate DataType="{x:Type vm:AllCustomersViewModel}">
    <vw:AllCustomersView />

Moving forward in building my project based on these patterns, creating my “conversation” view, attached properties came into play. I needed a particular behavior on one UI element to be triggered by another control’s itemssource’s event (on new item for instance). Searching the web, I heard about attached properties. But imagine my surprise when I saw my attached property only working for the first tab…

Read the rest of this entry