ILScene在WindowsFormsHost中不更新



我试图使用ILLinePlot来绘制使用WindowsFormsHost的WPF应用程序中的实时数据。我从这两个SO问题开始:在WindowsFormsHost &数字连续渲染图。

我的代码是: XAML:

<Window x:Class="Pulse_Generator.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:forms="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
        Title="MainWindow" Height="350" Width="525"
        Loaded="ILView_OnLoaded">
    <Grid Name="grid1">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <forms:WindowsFormsHost x:Name="WindowsFormsHost" Margin="5" />
    </Grid>
</Window>
c#:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
    private ILPanel ilPanel;
    private void IlPanelOnLoad(object sender, EventArgs eventArgs)
    {
        using (ILScope.Enter())
        {
            // generate some dummy data
            int N = 50000;
            ILArray<float> x = ILMath.vec<float>(0, N-1);
            ILArray<float> y = ILMath.tosingle(ILMath.rand(N));
            ILArray<float> A = ILMath.zeros<float>(2, N);
            A["0;:"] = x;
            A["1;:"] = y;
            ilPanel.Scene.Add(new ILPlotCube(){
                new ILLinePlot(A)
            });
            ilPanel.BeginRenderFrame += (o, args) =>
            {
                using (ILScope.Enter())
                {
                    var linePlot = ilPanel.Scene.First<ILLinePlot>();
                    var posBuffer = linePlot.Line.Positions;
                    ILArray<float> data = posBuffer.Storage;
                    // update the plot with some new dummy data
                    data["1;:"] = ILMath.tosingle(ILMath.randn(1, posBuffer.DataCount));
                    linePlot.Line.Positions.Update(data);
                    ilPanel.Scene.First<ILPlotCube>().Reset();
                    linePlot.Configure();
                }
            };
            // start running
            ilPanel.Clock.TimeMilliseconds = 15;
            ilPanel.Clock.Running = true;
        }
    }
    private void ILView_OnLoaded(object sender, RoutedEventArgs e)
    {
        ilPanel = new ILPanel();
        ilPanel.Load += IlPanelOnLoad;
        WindowsFormsHost.Child = ilPanel;
    }
}

问题是,只有当鼠标在绘图上交互(点击/拖动/滚动)或窗口大小被调整时,绘图才会更新(并且BeginRenderFrame似乎只会被触发)。

推测这是因为时钟没有正常运行在WindowsFormsHost?

没有太多的wpf经验,我认为你是对的:时钟在ILNumerics绘图面板使用应用程序。在WPF中未引起的空闲。

我在SO中发现了一个类似的帖子,描述了一个解决方案:应用程序。WPF应用程序中未触发空闲事件

根据那篇文章,你可以试试

ComponentDispatcher.ThreadIdle += (sender, e) => System.Windows.Forms.Application.RaiseIdle(e);

相关内容

  • 没有找到相关文章

最新更新