我有WPF窗口,它在WPF应用程序中托管时运行正常,但是当我从我的本机C++应用程序中加载它时,渲染和UI线程块需要很长时间才能完成.
我窗口上的主要攻击者是一系列项目控件,用于显示9到12个图标网格,这些图标代表我系统中组件的状态.
初始渲染的整个项目控制最多需要14秒.(在WPF应用程序中运行时几乎是即时的)
每行都有一个文本标题,单击该标题时会显示每个状态图标的小数据摘要(max,min,mean,std dev).单击此标题最多可能需要4秒才能呈现摘要,但在我的WPF应用程序中是即时的.
是否有任何已知的技巧使WPF在本机应用程序中表现良好?
[编辑]
我刚刚尝试使用以下代码从大型.NET窗体应用程序启动它:
public bool? ShowWpfDialog(System.Windows.Window window, Form owner)
{
var helper = new System.Windows.Interop.WindowInteropHelper(window)
{Owner = (owner == null) ? IntPtr.Zero : owner.Handle};
return window.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
我遇到与从本机应用程序运行时相同的性能问题.(.net应用程序也运行本机代码.)
[编辑]
当我不使用WindowInteropHelper时,代码执行正常:
public bool? ShowWpfDialog(System.Windows.Window window, Form owner)
{
//var helper = new System.Windows.Interop.WindowInteropHelper(window)
// {Owner = (owner == null) ? IntPtr.Zero : owner.Handle};
return window.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
什么是WindowInteropHelper会导致性能问题?
[编辑]
当我使用WindowInteropHelper向所有者加载资源时,是否存在资源解决方式的问题?
我们目前正在将项目从3.5版转换为.NET 4.5版.
我们设置了一个文本框IsEnabled,它使用多绑定转换器进行多重绑定.每个绑定都有自己的转换器.
一切都在.NET 3.5中运行良好,但在.NET 4.5中,传递给子转换器的目标类型是object类型而不是bool.
这是一个已知的问题?MS重构多重绑定,不将目标类型传递给子转换器.
我创建了一个简化的项目来演示这个问题.我在VS2008中创建了项目,然后将其转换为VS2012和.NET 4.5.
窗口XAML:
<Window x:Class="TestMultiBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestMultiBinding"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<local:NotConverter x:Key="NotConverter"/>
<local:MultiBoolConverter x:Key="MultiBoolConverter"/>
</Window.Resources>
<StackPanel>
<TextBox>
<TextBox.IsEnabled>
<MultiBinding Converter="{StaticResource MultiBoolConverter}">
<Binding Path="ConditionOne" />
<Binding Path="ConditionTwo" Converter="{StaticResource NotConverter}"/>
</MultiBinding>
</TextBox.IsEnabled>
</TextBox>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;
namespace TestMultiBinding
{
/// <summary>
/// Interaction logic for …Run Code Online (Sandbox Code Playgroud)