The following xaml works ok inside a Window
:
&l
When the XAML parser creates CroppedBitmap, it does the equivalent of:
var c = new CroppedBitmap();
c.BeginInit();
c.Source = ... OR c.SetBinding(...
c.SourceRect = ...
c.EndInit();
EndInit()
requires Source
to be non-null.
When you say c.Source=...
, the value is always set before the EndInit(), but if you use c.SetBinding(...)
, it tries to do the binding immediately but detects that DataContext
has not yet been set. Therefore it defers the binding until later. Thus when EndInit()
is called, Source
is still null.
This explains why you need a converter in this scenario.