Embedding WinForms Graph in WPF Window

前端 未结 4 1542
你的背包
你的背包 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:35

    Could you try the following code and see if you can get a graph to display and then work from there?

    MainWindow.xaml.cs

    using System.Collections.Generic;
    using System.Windows.Forms.DataVisualization.Charting;
    using System.Windows;
    
    namespace WpfApplication1
    {
        public partial class MainWindow : Window
        {
            Dictionary value;
            public MainWindow()
            {
                InitializeComponent();
    
                value = new Dictionary();
                for (int i = 0; i < 10; i++)
                    value.Add(i, 10 * i);
    
                Chart chart = this.FindName("MyWinformChart") as Chart;
                chart.DataSource = value;
                chart.Series["series"].XValueMember = "Key";
                chart.Series["series"].YValueMembers = "Value";
            }
        }
    }
    

    MainWindow.xaml

    
        
    
            
                
                    
                        
                    
                    
                        
                    
                
            
    
        
    
    

    making sure you have references to:

    %ProgramFiles%\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\WindowsFormsIntegration.dll

    %ProgramFiles%\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Windows.Forms.DataVisualization.dll

    %ProgramFiles%\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Windows.Forms.dll

    I have this running after shamelessly copying the following link

提交回复
热议问题