Page 1 of 1
WPF TeeChart with ElementHost
Posted: Wed Aug 15, 2012 7:37 am
by 15662946
Hi,
i have WPF teechart control inside an ElementHost(in winforms application).
i want the TeeChart to invoke the AfterDraw event.
i tried to use DoInvalidate,Invalidate,InvalidateVisual, ... and ElementHost.Referesh, ElementHost.Invalidate... , but i can't make the event invoke.
When does the afterdraw event occur and how can i make it invoke inside an ElementHost?
Re: WPF TeeChart with ElementHost
Posted: Thu Aug 16, 2012 8:33 am
by 10050769
Hello MVUser6,
Can you please try to arrange a simple code because we can reproduce your problem here? On the other hand, you can try use Bitmap in winforms or BitmapSource in WPF to repaint as do in next lines of code:
Code: Select all
Bitmap bmp = tChart1.Chart.Bitmap();
or
Code: Select all
BitmapSource bmp = tChart1.Chart.Bitmap();
Thanks,
Re: WPF TeeChart with ElementHost
Posted: Thu Aug 16, 2012 10:36 am
by 15662946
Here is a sample project.
i want to somehow make the teechart call the afterdraw, with function call from the elementhost\the teechart itself.
Re: WPF TeeChart with ElementHost
Posted: Thu Aug 16, 2012 1:39 pm
by 10050769
Hello MVUser6,
If you want TeeChart call AfterDraw Event, you must use the BitmapSource to achieve the Chart draw again. BitmapSource is behaved as bitmap and method Draw() of winforms. I have modified your button click event because the chart is repainted.
Code: Select all
public partial class Form1 : Form
{
private Steema.TeeChart.WPF.TChart TChartControl;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
InitTChartProperties();
}
private void InitTChartProperties()
{
this.SuspendLayout();
TChartControl = new Steema.TeeChart.WPF.TChart();
elementHost1.Visible = false;
this.pictureBox1.Controls.Add(this.elementHost1);
this.TChartControl.Aspect.View3D = false;
this.elementHost1.BackColor = System.Drawing.Color.Transparent;
this.elementHost1.Size = new System.Drawing.Size(916, 474);
this.TChartControl.TabIndex = 3;
Steema.TeeChart.WPF.Styles.Line line = new Steema.TeeChart.WPF.Styles.Line(TChartControl.Chart);
this.TChartControl[0].FillSampleValues();
this.TChartControl.AfterDraw = new Steema.TeeChart.WPF.PaintChartEventHandler(TChartControl_AfterDraw);
elementHost1.Child = TChartControl;
elementHost1.Dock = DockStyle.Fill;
this.ResumeLayout();
elementHost1.Visible = true;
}
void TChartControl_AfterDraw(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
{
richTextBox1.Text = "AfterDraw Invoked" Environment.NewLine;
}
private void button1_Click(object sender, EventArgs e)
{
elementHost1.Refresh();
BitmapSource bitmap = TChartControl.Chart.Bitmap();
}
Does it work as you expect?
Thanks,