我正在尝试在 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。 System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight) 在 System.Windows.Forms.Control.OnSizeChanged(EventArgs e) 在 System. 的 OnResize(EventArgs e) .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)