The following xaml works ok inside a Window:
<Border Width="45" Height="55" CornerRadius="10" >
<Border.Background>
<ImageBrush>
<ImageBrush.ImageSource>
<CroppedBitmap Source="profile.jpg" SourceRect="0 0 45 55"/>
</ImageBrush.ImageSource>
</ImageBrush>
</Border.Background>
</Border>
But when I use the equivalent code in a DataTemplate I get the following error in run-time:
Failed object initialization (ISupportInitialize.EndInit). 'Source' property is not set. Error at object 'System.Windows.Media.Imaging.CroppedBitmap' in markup file.
Inner Exception: {"'Source' property is not set."}
The only difference is that I have the CroppedBitmap's Source property data-bound:
<CroppedBitmap Source="{Binding Photo}" SourceRect="0 0 45 55"/>
What gives?
UPDATE: According to an old post by Bea Stollnitz this is a limitation of the source property of the CroppedBitmap, because it implements ISupportInitialize. (This information is down the page - do a search on "11:29" and you'll see).
Is this still an issue with .Net 3.5 SP1?