just found an interesting WPF problem I could really use your help with: I've got a multi-level binding Binding="{Binding PreviewItem.Status}
which produces strange behavior if and only if the properties are updated from a background thread. I used diagnostics:PresentationTraceSources.TraceLevel=High
and what seems to happen is that if Status is updated, it prevents the binding from realizing the whole PreviewItem changes just a split second after it!
I managed to reproduce the behavior in an new, empty C# test project (VS 2012, .NET 4.5). This is the main code: Both channel and TimelineItem are empty classes that just have a property with all the proper notifypropertychanged event notifications, StatusType is an Enum, the control's DataContext is set to _channel
:
Task.Run(() =>
{
if ( _channel.PreviewItem != null )
{
_channel.PreviewItem.Status = TimelineItem.StatusType.Default;
}
_channel.PreviewItem = new TimelineItem();
_channel.PreviewItem.Status = TimelineItem.StatusType.Preview;
});
}
Let's say we do this three times to create three items:
- A is created and assigned to PreviewItem, A's status goes to "Preview" (ok)
- A's status goes to Default, B is created and assigned to PreviewItem (fails, binding still uses A when the status changes, updates to the new state and never re-binds to B!)
- B's status goes to Default, C is created and assigned to PreviewItem (ok as the status of A - where the binding is still resolved to - does not change, therefore it notices that PreviewItem has changed to C).
If I a) move the exact same code to the main thread or b) assign the new PreviewItem BEFORE changing the old items status, the code works! Unfortunately, I cannot use either approach in my project.
Anyone got an idea why this does not work? As far as I understood it, WPF is supposed to take care of dispatching the change event to the proper dispatcher. Any help is highly appreciated...
Alex
UPDATE Aug 4, 2014 #
For some weird reason, the bug behavior only happens on Windows 7. Whole project can be found here.
UPDATE Sep 2, 2014
The problems was resolved in a Hotfix: http://support.microsoft.com/kb/2783808/en-us