【问题标题】:WPF ElementHost in Winforms crashes (Windows) when Maximized最大化时 Winforms 中的 WPF ElementHost 崩溃 (Windows)
【发布时间】:2011-10-10 22:59:53
【问题描述】:

我正在尝试将新的 WPF 控件集成到现有的 WinForms 应用程序中,并且我正在使用 ElementHost(Dock-Fill) 来托管以下 XAML UserControl。 (.NET 4)

当我将 WinForm 设置为最大化时,我的整个操作系统崩溃了。我已经为我的视频卡更新了最新的 NVidia 驱动程序,但我仍然在 nvlddmkm.sys 中看到了蓝屏。我四处寻找其他遇到此类崩溃的人,但除了“更新显卡驱动程序”之外没有找到任何其他内容。

UserControl 中指定的 CustomerOrderReadyControl 是用 C# 编写的,但鉴于它只是一个显示 Message 的基本 UserControl,我没有包含它,但如果您认为我应该包含它,请在 cmets 中指定。

当我最大化表单时,我是否缺少可能导致我的应用程序导致机器蓝屏的设置? 鉴于现有应用程序非常繁重的 GDI+ 用于渲染应用程序的其他部分,是否有任何其他方法可以使这个场景工作?

<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>

我的 WinForms 中的 InitializeComponent sub 就是这么简单。

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

编辑: 附加信息.. 如果我在纯 WPF 应用程序中托管此控件并最大化 WPF 表单,那么一切正常。

【问题讨论】:

  • 这是否只在一台机器上失败?如果是这样,您可以尝试以下故障排除设置:msdn.microsoft.com/en-us/library/aa970912.aspx
  • 我的机器很遗憾。英伟达 Quadro NVS295。在另一台机器上测试,没问题。看起来像是用什么东西来代替这张糟糕的卡片......但是它会在分发时咬我。
  • 尝试了那里提到的各种设置,仍然崩溃

标签: .net wpf xaml wpf-controls winforms-interop


【解决方案1】:

原来这是显卡 (NVidia NVS295) 只是没有处理 WPF 操作。如果屏幕显示全屏(1900x1200)然后机器蓝屏,它最终是在完整的 WPF 应用程序中还是嵌入在 ElementHost 中都无关紧要。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多