I'm having an annoying problem with WPF binding. Basically, I declare a FrameworkElement in my UserControl's resources, but that item doesn't seem to get notified when the DataContext of the parent UserControl changes.
Basically, in my UserControl I have a Popup in the ItemTemplate for an ItemsControl. In that Popup, I needed to bind to something in the parent view's ViewModel, so I came up with what I thought was a clever trick. Taking a cue from CollectionViewSource, I figured I'd just bind my parent's view model to a resource, and then use that resource to get to the ViewModel from the DataTemplate, like so:
<UserControl.Resources>
<cont:ViewModelSource Source="{Binding}" x:Key="ParentViewModel"/>
</UserControl.Resources>
So that later I can use it like:
CommandParameter="{Binding ViewModel.OpenEntity, Source={StaticResource ParentViewModel}}"
This all would seem to work except that the DataContext on the ViewModelSource doesn't get reset when the DataContext of the UserControl gets reset. Right now, I'm making this work hackily: setting the resource's DataContext in code-behind on the UserControl's DataContextChanged event.
I took a look in Reflector to see how CollectionViewSource does this, but it doesn't seem to be doing anything special.
Anyone know why this is happening or how I can fix it?