I was trying to bind an BitmapImage to WPF’s Image.Source property.

Somehow the image kept not showing up so I added some WPF binding diagnostics:


This how my Image control looked like at the end:

<Image Source=”{Binding FrontImage, trace:PresentationTraceSources.TraceLevel=High}” Initialized=”imgFrontScan_Initialized” />

Looking at the Output window I saw Deactivate and Detach events for BindingExpression like the ones below:

System.Windows.Data Warning: 75 : BindingExpression (hash=33476626): Deactivate
System.Windows.Data Warning: 99 : BindingExpression (hash=33476626): Replace item at level 0 with {NullDataItem}
System.Windows.Data Warning: 59 : BindingExpression (hash=33476626): Detach

It took me few hours to find out what is happening but it finally hit me when I read that any change of DataContext will cause binding to detach.

In my case I have implemented event handler imgFrontScan_Initialized handing the Initialized event. In there I was creating a dynamically generated image and getting it assigned to the image’s Source property. This made DataContext to change and effectively detach the binding.

The simple solution was just to remove the event handler as I did not really needed it.

I hope this will save you few hours of debugging.