Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding WinForms Graph in WPF Window

I've tried to embed a .NET WinForms graph (Stephan Zimmermann's Graph Display) in a WPF window, under a WindowsFormsHost (I've referenced both System.Windows.Forms and WindowsFormsIntegration).

However, I can see the form panel but not the graph. I've ran the demo application on a windows form and it worked, but when I transfered the same code to the WPF window, I saw that the data is updated but not shown on the graph.

Thank everyone in advance,

Yaron.

like image 684
Yaron Adler Avatar asked Mar 04 '10 08:03

Yaron Adler


1 Answers

Although the question is more than 6 years old I had a similar (if not the same issue), when trying to create and add the Chart object at runtime. Thanks to Bobwah's suggestion I could isolate the problem and found that I simply had to add a ChartArea to the Chart object to see the graph:

Chart chart = new Chart();
chart.ChartAreas.Add("MainChartArea"); //this was missing
chart.Series.Add(getSeries());
chart.Dock = System.Windows.Forms.DockStyle.Fill;
host.Child = chart; //'host' is the WPF-WindowsFormsHost control

Hope it helps someone... ;)

like image 153
Reinski Avatar answered Sep 30 '22 22:09

Reinski