WPF ElementHost in Winforms crashes (Windows) when Maximized

末鹿安然 提交于 2019-12-04 06:02:51

问题


I'm trying to integrate a new WPF control into an existing WinForms application and I'm using an ElementHost(Dock-Fill) to host the following XAML UserControl. (.NET 4)

When I set the WinForm to Maximised my entire operating system crashes. I have updated to the latest NVidia Drivers for my video card, but I still end up with a BlueScreen in nvlddmkm.sys. I have searched around for others that are experiencing crashes like this, but haven't found anything other than "update video card drivers".

The CustomerOrderReadyControl specified in the UserControl is in C#, but given it's just a basic UserControl that displays the Message I haven't included it, but if you think I should, please specify in the comments.

Is there a setting that I am missing that could be causing my Application to be causing the Machine to bluescreen when I maximise the Form? Are there any other ways that I could make this scenario work given that the existing application is very heavy GDI+ for the rendering of other parts of the application?

<UserControl x:Class="WPFDisplay.CustomerOrderDisplayControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 
    d:DesignHeight="480" d:DesignWidth="640" xmlns:my="clr-namespace:WPFDisplay">
    <UserControl.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="#FFEEEEEE" Offset="0.05"/>
            <GradientStop Color="#FF333333" Offset="0.95"/>
        </LinearGradientBrush>
    </UserControl.Background>
        <Grid Name="mainGrid">

        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition  Name="imageRow" Height="125" />
        </Grid.RowDefinitions>

        <my:CustomerOrderReadyControl Grid.Row="0"  x:Name="customerOrderReadyControl1" 
               Message="The Message" />
        <Image Margin="0,0,6,7" Name="displayLogo" Grid.Row="1" VerticalAlignment="Bottom" 
               HorizontalAlignment="Right" Width="302" Height="107" Stretch="None" IsHitTestVisible="False" />
    </Grid>
</UserControl>

The InitializeComponent sub in my WinForms is really this simple.

Private Sub InitializeComponent()
    Me.ElementHost1 = New System.Windows.Forms.Integration.ElementHost()
    Me.CustomerOrderDisplayControl1 = New WPFDisplay.CustomerOrderDisplayControl()
    Me.SuspendLayout()
    '
    'ElementHost1
    '
    Me.ElementHost1.Dock = System.Windows.Forms.DockStyle.Fill
    Me.ElementHost1.Location = New System.Drawing.Point(0, 0)
    Me.ElementHost1.Name = "ElementHost1"
    Me.ElementHost1.Size = New System.Drawing.Size(1058, 617)
    Me.ElementHost1.TabIndex = 0
    Me.ElementHost1.Text = "ElementHost1"
    Me.ElementHost1.Child = Me.CustomerOrderDisplayControl1
    '
    'CustomerOrderDisplayForm
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(1058, 617)
    Me.Controls.Add(Me.ElementHost1)
    Me.Name = "CustomerOrderDisplayForm"
    Me.Text = "CustomerOrderDisplayForm"
    Me.ResumeLayout(False)

End Sub

EDIT: Additional info.. If I host this control in a Pure WPF application and maximise the WPF Form, then it all works fine.


回答1:


Turns out this was the video card (NVidia NVS295) just not handling the WPF operations. It ended up not mattering whether it was in a full blown WPF application or embedded inside an ElementHost if the screen display full screen (1900x1200) then the machine bluescreened.



来源:https://stackoverflow.com/questions/7719627/wpf-elementhost-in-winforms-crashes-windows-when-maximized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!