WindowsFormsHost中的ILScene [英] ILScene in WindowsFormsHost

查看:112
本文介绍了WindowsFormsHost中的ILScene的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在WPF的WindowsFormsHost控件中托管ILPanel.这是我的代码:

I am trying to host an ILPanel in a WindowsFormsHost Control in WPF. Here's my code:

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;引发参数异常:参数无效".堆栈跟踪:

The line WindowsFormsHost.Child = ilPanel; throws an Argument Exception: "Parameter is not valid." Stack Trace:

at System.Drawing.Bitmap..ctor(Int32 width,Int32 height, PixelFormat格式)位于 ILNumerics.Drawing.ILBackBuffer.set_Rectangle(矩形值)在 ILNumerics.Drawing.ILGDIDriver.set_Size(大小值)在 ILNumerics.Drawing.ILOGLControl.OnResize(EventArgs e)在 System.Windows.Forms.Control.OnSizeChanged(EventArgs e)在 System.Windows.Forms.Control.UpdateBounds(Int32 x,Int32 y,Int32 宽度,Int32高度,Int32 clientWidth,Int32 clientHeight) System.Windows.Forms.Control.UpdateBounds()在 System.Windows.Forms.Control.WmWindowPosChanged(Message&m)位于 System.Windows.Forms.Control.WndProc(Message&m)位于 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,IntPtr wparam,IntPtr lparam)

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控件认为"要在设计器中使用.因此,您发现了设计时间替换(圆圈").

If the rendering controls of ILNumerics are not loaded from a regular application, you will have to give a hint, in order to distinguish regular rendering from design time behavior. Frameworks, which load the library dynamically at runtime (VSTO, devenv, LinqPad and obviously MEF) may cause ILNumerics controls to 'think' to be used in a designer. Hence the design time replacement ('circle') you found.

为了使ILNumerics呈现运行时方式",请在app.config中添加以下设置:

In order to make ILNumerics render the 'runtime way' instead, add the following setting to your app.config:

key="ILNIsHosted" value="true"

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

In the context of the app.config settings file:

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

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

The use of the app.config enables the application of the setting even in those scenarios, where the framework does not allow user code to be executed before the setup of any control. If your framework provides some initialization hook, you may just as well do the configuration by code:

ILNumerics.Settings.IsHosted = true; 

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

Keep in mind, that this code needs to be executed early in the application setup. At latest before ILPanel is initialized. Otherwise, the use of app.config is recommended.

这篇关于WindowsFormsHost中的ILScene的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆