Q: Image not taking whole of the space in the DataGridCell I have a Datagrid, which shows thumbnails of some image files along with other data. I am using a converter to crop part of an image and then show that cropped image in the Datagrid. Here is the screenshot of the grid:

The image is showing fine, but it is very small.If I change the width of columns using mouse, then there is change in the image's width. But the image is not taking full space in the cell.Below is the code that I am using:
<DataGrid Grid.Row="1" Grid.Column="1"  Grid.ColumnSpan="1"  RowHeight="30" x:Name="dgFileDetails" CanUserAddRows="False"  AutoGenerateColumns="False"  SelectionMode="Single" CellEditEnding="dgFileDetails_CellEditEnding" SelectionChanged="dgFileDetails_SelectionChanged" MouseDoubleClick="dgFileDetails_MouseDoubleClick" AlternatingRowBackground="{StaticResource LightGrayColorBrush}" GridLinesVisibility="None" CurrentCellChanged="dgFileDetails_CurrentCellChanged" >
    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridCell}" x:Key="TextCellStyle">
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
        <Style TargetType="{x:Type DataGridCell}" x:Key="ImageCellStyle">
            <Setter Property="VerticalAlignment" Value="Stretch"></Setter>
            <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
            <Setter Property="VerticalContentAlignment" Value="Stretch"></Setter>
        </Style>
    </DataGrid.Resources>
    <DataGrid.Columns>
        <DataGridTextColumn IsReadOnly="False" Width="2*" Header="Sheet Name" Binding="{Binding NewFileName}" />
        <DataGridTextColumn IsReadOnly="False" Width="1*" Header="Label" Binding="{Binding FileId}" />
        <DataGridTextColumn IsReadOnly="False" Width="1*" Header="Trade" Binding="{Binding Trade}" />
        <DataGridTextColumn IsReadOnly="False" Width="1*" Header="Sub-Trade" Binding="{Binding SubTrade}" />
        <DataGridTextColumn IsReadOnly="False" Width="1*" Header="Version" Binding="{Binding VersionName}" />
        <DataGridTextColumn IsReadOnly="False" Width="0.5*" Header="Revision" Binding="{Binding RevisionNo}" />
        <DataGridTemplateColumn Header="Sheet Title" Width="1*" IsReadOnly="True" CellStyle="{StaticResource ImageCellStyle}">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image Source="{Binding TitleImage,Converter={StaticResource ConverterTupleToImage}}" Stretch="Fill" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTemplateColumn Header="Sheet Label" Width="1*" IsReadOnly="True" CellStyle="{StaticResource ImageCellStyle}">
            <DataGridTemplateColumn.CellTemplate >
                <DataTemplate>
                    <Image Source="{Binding IdImage,Converter={StaticResource ConverterTupleToImage}}"  Stretch="Fill"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

It can be seen that I have set all the alignment properties of the cell to stretch, but it does not help.So, how do I make the Image element to take whole of the DataGridCell's space.
Edit: Here is the code for the converter:
public object Convert(object value,Type targetType,object parameter,CultureInfo cultureInfo)
{
    try
    {
        if (value is Tuple<Tuple<int, int, int, int>, string>)
        {
            Tuple<Tuple<int, int, int, int>, string> tuple = value as Tuple<Tuple<int, int, int, int>, string>;
            Tuple<int, int, int, int> rectDims = tuple.Item1;
            string filePath = tuple.Item2;
            using (MyDocument doc = MyDocument.Load(filePath))
            {
                var size = doc.Size;
                int width = (int)(size.Width);
                int height = (int)(size.Height);
                Rectangle cropSection = new Rectangle(rectDims.Item1, rectDims.Item3, Math.Abs(rectDims.Item1 - rectDims.Item2), Math.Abs(rectDims.Item3 - rectDims.Item4));
                using (Image image = doc.Render(0, width, height, 300, 300, false))
                {
                    Bitmap targetRect = new Bitmap(cropSection.Width, cropSection.Height);
                    using (Graphics g = Graphics.FromImage(targetRect))
                    {
                        g.DrawImage(image, 0, 0, cropSection, GraphicsUnit.Pixel);
                    }
                    return BitmapConverter.ToImageSource(targetRect);
                }
            }
        }
        else
        {
            return null;
        }
    }
    catch (Exception ex)
    {
        return null;
    }
}


A: The issue was solved by using the CroppedBitmap class(suggested by Clemens in comments). I do not know the reason,but below is the code that I used:
public object Convert(object value,Type targetType,object parameter,CultureInfo cultureInfo)
{
    try
    {
        if (value is Tuple<Tuple<int, int, int, int>, string>)
        {
            Tuple<Tuple<int, int, int, int>, string> tuple = value as Tuple<Tuple<int, int, int, int>, string>;
            Tuple<int, int, int, int> rectDims = tuple.Item1;
            string filePath = tuple.Item2;
            using (MyDocument doc = MyDocument.Load(filePath))
            {
                var size = doc.Size;
                int width = (int)(size.Width);
                int height = (int)(size.Height);
                Rectangle cropSection = new Rectangle(rectDims.Item1, rectDims.Item3, Math.Abs(rectDims.Item1 - rectDims.Item2), Math.Abs(rectDims.Item3 - rectDims.Item4));
                using (Image image = doc.Render(0, width, height, 300, 300, false))
                {
                    BitmapSource sourceImage = BitmapHelper.ToBitmapSource(image);
                    CroppedBitmap croppedImage = new CroppedBitmap(sourceImage,new System.Windows.Int32Rect(cropSection.X,cropSection.Y,cropSection.Width,cropSection.Height));
                    return croppedImage;
                }
            }
        }
        else
        {
            return null;
        }
    }
    catch (Exception ex)
    {
        return null;
    }
}

