我正在尝试在 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;
抛出参数异常:“参数无效。”堆栈跟踪:
在 System.Drawing.Bitmap..ctor(Int32 宽度,Int32 高度,
PixelFormat 格式)位于
ILNumerics.Drawing.ILBackBuffer.set_Rectangle(矩形值)位于
ILNumerics.Drawing.ILGDIDriver.set_Size(大小值)位于
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
宽度、Int32 高度、Int32 客户端宽度、Int32 客户端高度)位于
System.Windows.Forms.Control.UpdateBounds() 位于
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 也可以应用该设置before任何控件的设置。如果您的框架提供了一些初始化钩子,您也可以通过代码进行配置:
ILNumerics.Settings.IsHosted = true;
请记住,此代码需要在应用程序设置的早期执行。最迟在 ILPanel 初始化之前。否则,建议使用 app.config。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)