It' a Bug in WPF.
This bug can be avoided by hiding the ImageControl from the mouse.
public void DataGrid()
{
StampModel stampModel = new StampModel();
Type type = stampModel.GetType();
foreach (var property in type.GetProperties())
{
if (property.Name != "ImageSource")
{
CreateGridColumn(property.Name);
}
else
{
DataGridTemplateColumn ImageCol = new DataGridTemplateColumn();
ImageCol.Header = "Image";
ImageCol.Width = 120;
ImageCol.IsReadOnly = true;
FrameworkElementFactory imageFactory = new FrameworkElementFactory(typeof(Image));
imageFactory.SetBinding(Image.SourceProperty, new Binding("ImageSource"));
FrameworkElementFactory gridFactoryInner = new FrameworkElementFactory(typeof(Grid));
gridFactoryInner.SetValue(Grid.BackgroundProperty, Brushes.Transparent);
FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid));
gridFactory.AppendChild(imageFactory);
gridFactory.AppendChild(gridFactoryInner);
DataTemplate dataTemplate = new DataTemplate();
dataTemplate.VisualTree = gridFactory;
//<DataTemplate>
// <Grid>
// <Image Source="{Binding Path=ImageSource}" />
// <Grid Background="Transparent" x:Name="dummyGrid"/>
// </Grid>
//</DataTemplate>
ImageCol.CellTemplate = dataTemplate;
Style ImageColumnStyle = new Style();
ImageColumnStyle.TargetType = typeof(DataGridCell);
ImageCol.CellStyle = ImageColumnStyle;
dataGrid.Columns.Add(ImageCol);
}
}