32位Windows 7和Windows 8.1上的WPF渲染问题

时间:2017-09-25 12:39:44

标签: c# .net wpf

我有一个WPF应用程序,我尝试在多个VM上安装。在每个64位Windows上它运行正常,但在每个32位窗口上,WPF应用程序UI响应都很糟糕。

32位计算机上的WPF应用程序有什么特别之处吗?

2 个答案:

答案 0 :(得分:1)

感谢@swiszcz领导,我通过在应用程序启动方法中添加以下代码,设法解决了Win 7和Win 8.1 x86 VM上的渲染问题:

RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;

编辑:为了完全最优,我现在检查程序是在物理机器上还是在虚拟机上运行。在虚拟机上,我将RenderMode设置为SoftwareOnly,并在物理机器上将RenderMode设置为Default。

以下是执行此操作的代码:

public partial class App : Application
{

    public App()
    {
        Startup += Application_Startup;
        Exit += Application_Exit;

        InitializeComponent();
    }

    /// <summary>
    /// Detect if the local machine is a virtual or a physical one
    /// </summary>
    /// <returns>True if the local machine is virtual, False if the local machine is physical</returns>
    private bool IsVirtualMachine()
    {
        using (var searcher = new System.Management.ManagementObjectSearcher("Select * from Win32_ComputerSystem"))
        {
            using (var items = searcher.Get())
            {
                foreach (var item in items)
                {
                    string manufacturer = item["Manufacturer"].ToString().ToLower();
                    if ((manufacturer == "microsoft corporation" && item["Model"].ToString().ToUpperInvariant().Contains("VIRTUAL"))
                        || manufacturer.Contains("vmware")
                        || item["Model"].ToString() == "VirtualBox")
                    {
                        return true;
                    }

                    // Check "HypervisorPresent" property, which is available in some cases.
                    var hypervisorPresentProperty
                      = item.Properties
                            .OfType<PropertyData>()
                            .FirstOrDefault(p => p.Name == "HypervisorPresent");

                    if ((bool?)hypervisorPresentProperty?.Value == true)
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }

   private void Application_Startup(object sender, StartupEventArgs e)
    {
        //Alter the rendering for the virtual machine (see Bug 
        if (this.IsVirtualMachine())
            RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
        else
            RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.Default;

    }
}

答案 1 :(得分:0)

我假设您正在使用部署的Click Once选项,您需要首先检查所有依赖项,并确保所有依赖项都与x86兼容,如果它们进入您的项目属性,请确保在Build下平台目标确保选中任何CPU。这是我要开始的地方。