Save element (inherited from System.Windows.Controls.Control) as image using below code.
RenderTargetBitmap bmpSource = new RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bmpSource.Render(element);
imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
using (Stream stream = File.Create(fileName))
{
imgEncoder.Save(stream);
}
Works fine when element present in 0 th row, not works for 1st row inside grid. By as a workaround, added inside the stackpanel and then grid it works.
80054-customcontrol.txt
[Xaml]
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="25*"/>
<RowDefinition Height="75*"/>
</Grid.RowDefinitions>
. . .
<local:CustomControl x:Name="StackingColumnChart2" Template="{StaticResource Template}" Grid.Row="1"/>
. . .