wpf - WindowsFormsHost 中的 ILScene

标签 wpf ilnumerics

我正在尝试在 WPF 的 WindowsFormsHost 控件中托管 ILPanel。这是我的代码:

XAML:

<Window x:Class="ILNumericsCharacteristicViewer.ILView"
    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="ILView"
    Width="300"
    Height="300"
    Loaded="ILView_OnLoaded">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="auto" />
    </Grid.RowDefinitions>

    <forms:WindowsFormsHost x:Name="WindowsFormsHost" Margin="5" />

    <Button x:Name="ButtonClose"
            Grid.Row="1"
            HorizontalAlignment="Right"
            Click="ButtonClose_OnClick"
            Content="Close" />
</Grid>

代码隐藏:

public partial class ILView : Window
{
    private ILPanel ilPanel;

    public ILView()
    {
        InitializeComponent();
    }

    private void IlPanelOnLoad(object sender, EventArgs eventArgs)
    {
        ILArray<float> A = ILMath.tosingle(ILMath.rand(3, 10000));

        var scene = new ILScene {
    new ILPlotCube(twoDMode: false) {
        new ILPoints {
            Positions = A,
            Color = null,
            Colors = A,
            Size = 2,
                    }
                }
        };
        var pcsm = scene.First<ILPlotCube>().ScaleModes;
        pcsm.XAxisScale = AxisScale.Logarithmic;
        pcsm.YAxisScale = AxisScale.Logarithmic;
        pcsm.ZAxisScale = AxisScale.Logarithmic;

        ilPanel.Scene = scene;
    }

    private void ButtonClose_OnClick(object sender, RoutedEventArgs e)
    {
        Close();
    }

    private void ILView_OnLoaded(object sender, RoutedEventArgs e)
    {
        ilPanel = new ILPanel();
        ilPanel.Load += IlPanelOnLoad;
        WindowsFormsHost.Child = ilPanel;
    }
}

WindowsFormsHost.Child = ilPanel; 引发参数异常:“参数无效。”堆栈跟踪:

at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at ILNumerics.Drawing.ILBackBuffer.set_Rectangle(Rectangle value) at ILNumerics.Drawing.ILGDIDriver.set_Size(Size value) at ILNumerics.Drawing.ILOGLControl.OnResize(EventArgs e) at System.Windows.Forms.Control.OnSizeChanged(EventArgs e) at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight) at System.Windows.Forms.Control.UpdateBounds() at System.Windows.Forms.Control.WmWindowPosChanged(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

最佳答案

如果 ILNumerics 的呈现控件不是从常规应用程序加载的,则必须给出提示,以便将常规呈现与设计时行为区分开来。在运行时动态加载库的框架(VSTO、devenv、LinqPad 和显然是 MEF)可能会导致 ILNumerics 控件“认为”在设计器中使用。因此,您找到了设计时替换(“圆圈”)。

为了使 ILNumerics 呈现“运行时方式”,请将以下设置添加到您的 app.config 中:

key="ILNIsHosted" value="true"

在 app.config 设置文件的上下文中:

<configuration>
  <appSettings>
    <add key="ILNIsHosted" value="true"/>
  </appSettings>
</configuration>

即使在框架不允许在设置任何控件之前执行用户代码的情况下,使用 app.config 也可以应用设置。如果您的框架提供了一些初始化 Hook ,您也可以通过代码进行配置:

ILNumerics.Settings.IsHosted = true; 

请记住,此代码需要在应用程序设置的早期执行。最晚在 ILPanel 初始化之前。否则,建议使用 app.config。

关于wpf - WindowsFormsHost 中的 ILScene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18314146/

相关文章:

c# - SQLite 错误 : The 'DbProviderFactories' section can only appear once per config file (IBM Client Access)

WPF 通过事件调用命令

c# - 初学者 ILNumerics : install under VS2012

c# - 异步调用时 ILNumerics 内存损坏

c# - 不工作绑定(bind)

c# - 动画wpf列表框的选定项目

c# - MVVM设计模式问题

c# - 如何更改 ILNumerics 绘图标记类型?

plot - 如何在 ILNumerics 中有效地绘制大表面(例如 1000x1000)?

csv - 如何在 ILArray 中加载大 CSV 文件进行 3d 绘图?