private void Button_Click(object sender, RoutedEventArgs e)
{
Save("Series Number: example Prefix: example Temparature: 25,8");
}
private void Save(string text=null)
{
TextBlock textBlock = null;
if (text != null)
{
textBlock = new TextBlock()
{
Text = text,
FontFamily = new FontFamily("Arial"),
FontSize = 17,
Margin = new Thickness(90, 30, 0, 0)
};
grid.Children.Add(textBlock);
}
sfChart.GetType().GetMethod("RenderSeries", BindingFlags.NonPublic |
BindingFlags.Instance).Invoke(sfChart, null);
sfChart.UpdateLayout();
grid.UpdateLayout();
RenderTargetBitmap bmpSource = new RenderTargetBitmap((int)grid.ActualWidth, (int)grid.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bmpSource.Render(grid);
BitmapEncoder imgEncoder = new PngBitmapEncoder();
imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
using (Stream stream = File.Create(@"D:\chart.png"))
{
imgEncoder.Save(stream);
}
if (textBlock !=null)
grid.Children.Remove(textBlock);
} |
private void Save(string text=null)
{
textBlock.Text = text;
grid1.Measure(new Size(width, height));
grid1.Arrange(new Rect(0, 0, width, height));
grid1.UpdateLayout();
RenderTargetBitmap bmpSource = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
bmpSource.Render(grid1);
BitmapEncoder imgEncoder = new PngBitmapEncoder();
imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
using (Stream stream = File.Create(@"D:\chart.png"))
{
imgEncoder.Save(stream);
}
}
private void TabControl_Loaded(object sender, RoutedEventArgs e)
{
...
sfChart.Measure(new Size(width, height));
sfChart.Arrange(new Rect(0, 0, width, height));
sfChart.GetType().GetMethod("RenderSeries", BindingFlags.NonPublic |
BindingFlags.Instance).Invoke(sfChart, null);
sfChart.UpdateLayout();
SfChart chart = sfChart.Clone() as SfChart;
chart.Measure(new Size(width, height));
chart.Arrange(new Rect(0, 0, width, height));
chart.GetType().GetMethod("RenderSeries", BindingFlags.NonPublic |
BindingFlags.Instance).Invoke(chart, null);
chart.UpdateLayout();
grid1.Children.Add(chart);
textBlock = new TextBlock()
{
FontFamily = new FontFamily("Arial"),
FontSize = 17,
Margin = new Thickness(90, 30, 0, 0)
};
grid1.Children.Add(textBlock);
} |
ImageChart.InvokeBaseMethod("RenderSeries");
if (ImageChart.Legend != null)
{
(ImageChart.Legend as UIElement).Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
}
ImageChart.InvokeBaseMethod("UpdateArea", true); |