本文介绍了在 WPF 窗口中嵌入 WinForms Graph的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我尝试在 WindowsFormsHost 下的 WPF 窗口中嵌入 .NET WinForms 图形(Stephan Zimmermann 的图形显示)(我参考了 System.Windows.Forms 和 WindowsFormsIntegration).

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

但是,我可以看到表单面板,但看不到图表.我已经在 Windows 窗体上运行了演示应用程序并且它工作正常,但是当我将相同的代码传输到 WPF 窗口时,我看到数据已更新但未显示在图表上.

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.

提前谢谢大家,

亚伦.

推荐答案

你能试试下面的代码,看看你能不能得到一个图形来显示,然后从那里开始工作?

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

MainWindow.xaml.cs

MainWindow.xaml.cs

using System.Collections.Generic;
using System.Windows.Forms.DataVisualization.Charting;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        Dictionary<int, double> value;
        public MainWindow()
        {
            InitializeComponent();

            value = new Dictionary<int, double>();
            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";
        }
    }
}

主窗口.xaml

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:winformchart="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization"
    Title="MainWindow" Height="392" Width="525">
    <StackPanel>

        <WindowsFormsHost x:Name="host" Height="300">
            <winformchart:Chart x:Name="MyWinformChart" Dock="Fill">
                <winformchart:Chart.Series>
                    <winformchart:Series Name="series" ChartType="Line"/>
                </winformchart:Chart.Series>
                <winformchart:Chart.ChartAreas>
                    <winformchart:ChartArea/>
                </winformchart:Chart.ChartAreas>
            </winformchart:Chart>
        </WindowsFormsHost>

    </StackPanel>
</Window>

确保您参考了:

%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0ProfileClientWindowsFormsIntegration.dll

%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0ProfileClientWindowsFormsIntegration.dll

%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0ProfileClientSystem.Windows.Forms.DataVisualization.dll

%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0ProfileClientSystem.Windows.Forms.DataVisualization.dll

%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0ProfileClientSystem.Windows.Forms.dll

%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0ProfileClientSystem.Windows.Forms.dll

我在无耻地复制以下内容后运行了这个链接

I have this running after shamelessly copying the following link

这篇关于在 WPF 窗口中嵌入 WinForms Graph的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:43