WindowsFormsHost白色第一次

时间:2012-08-22 10:45:49

标签: wpf activex windowsformshost

我有一个WPF窗口,它基本上占据了整个空间:

<WindowsFormsHost Grid.RowSpan="2" Name="wfh" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Cursor="IBeam" ForceCursor="True" SnapsToDevicePixels="True" >
    <ax:AxViewerActiveX x:Name="_axViewer" AutoSize="True"  Cursor="Cross" Margin="0,0,0,0" Padding="0,0,0,0" UseWaitCursor="True">
    </ax:AxViewerActiveX>
</WindowsFormsHost>

我第一次执行此窗口的ShowDialog()时,窗口显示为空白: enter image description here

它应该第二次出现:

enter image description here

请问,有人可以帮助第一次正确渲染窗口吗?

此窗口类的构造函数:

this.InitializeComponent();
_axViewer.BeginInit();
_axViewer.EndInit();

Focus();
_axViewer.Focus();

调用它时很简单:

w3d.WindowState = WindowState.Maximized;
w3d.ShowDialog();

1 个答案:

答案 0 :(得分:1)

尝试将ActiveX控件的初始化放在.Loaded()方法中?

this.InitializeComponent();
Loaded += delegate {
    _axViewer.BeginInit();
    _axViewer.EndInit();

    Focus();
    _axViewer.Focus();
};