如何分析WPF 4.5 UI性能性能、WPF、UI

2023-09-02 01:51:05 作者:在劫难逃

我正在开发一个.NET 4.5 WPF应用程序,并具有UI渲染性能问题。

一些google搜索后,我碰到 WPF性能套件页面描述正是我所需要的工具 - 可视化探查。它允许查看WPF元素树和分析各元素的总渲染时间的贡献。

唯一的问题是,在页面指出工具被包含在其中的目标是Windows 7和.NET 4.0的Microsoft Windows SDK v7.1的

由于我的应用程序是.NET 4.5和我在Windows 8.1,我已经安装的 Windows SDK的Windows 8.1 。令我惊讶的是,它似乎并没有包含WPF性能套件的一切,尤其是工具。

然后,我试着安装在 WPF性能套件从这个回答, ,但它只能在.NET 4.0应用

因此​​,你在哪里得到的WPF性能套件.NET 4.5的应用程序? 或者,更一般的,如何您的个人资料的.NET 4.5应用程序的WPF UI渲染性能,找出它在树中的元素在复杂的UI最高性能的影响?

解决方案

最后,我发现,我一直在寻找一个工具,这对我来说非常有帮助。

要获得确切位置是在渲染你的WPF布局瓶颈的想法,你想:

安装的Visual Studio 2015年后,如果您还没有一个:) 转到调试 - > 开始诊断工具不调试 检查应用程序时间表工具,并点击开始在这样的观点:

当你的应用程序启动,执行的操作导致的问题你有兴趣 研究。 然后点击停止录制,你最终会得到你的元素 树与花时间进行渲染的每个节点。 然后,你只需要通过持续时间(总)并扩大最慢的节点,直到找到问题排序是: WPF界面设计快速生成软件 UI for WPF

在最后,它会更容易从树中的节点与你的布局,如果你设置使用名称的名称为您的控件属性类似下面的关联以上:

 < TextBlock的名称=OwnerContact>
 

I'm developing a .NET 4.5 WPF app and having UI rendering performance issues.

After some googling, I came across WPF Performance Suite page which describes exactly the tool I need - Visual Profiler. It allows to view WPF elements tree and analyze the contribution of each element to the total rendering time.

The only problem is that the page states that the tool is contained in Microsoft Windows SDK v7.1 which is targeting Windows 7 and .NET 4.0.

Since my app is for .NET 4.5 and I'm on Windows 8.1, I've installed Windows SDK for Windows 8.1. To my surprise, it doesn't seem to contain the WPF Performance Suite at all and that tool in particular.

Then, I've tried to install the WPF Performance Suite from this answer, but it works only with .NET 4.0 apps.

So, where do you get the WPF Performance Suite for .NET 4.5 apps? Or, to be more general, how do you profile WPF UI rendering performance of .NET 4.5 apps to find out which elements in the tree have highest performance impact in complex UIs?

解决方案

Eventually, I've found a tool that I was looking for and that was really helpful for me.

To get an idea of where exactly is the bottleneck in rendering your WPF layout, you want to:

Install the Visual Studio 2015, if you don't have one yet :) Go to Debug -> Start Diagnostic Tools Without Debugging Check Application Timeline tool and hit Start in this view:

When your app starts, do the actions causing issues you're interested in. Then hit Stop recording and you'll eventually get your elements tree with times spent for rendering every node. Then, you only need to sort it by Duration (total) and expand slowest nodes until you find the problem:

In conclusion, it would much easier to correlate the nodes from tree above with your layout if you set names for your controls using the Name attribute like the following:

<TextBlock Name="OwnerContact">