Embedding WinForms Graph in WPF Window

前端 未结 4 1562
你的背包
你的背包 2020-12-17 18:42

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 Wi

4条回答
  •  悲&欢浪女
    2020-12-17 19:20

    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... ;)

提交回复
热议问题