Horrible WPF performance!
Why am i using over 80% CPU when just hovering some links? As you can see in the video i uploaded: http://www.youtube.com/watch?v=3ALF9NquTRE the CPU goes to >80% CPU when i move my mouse over the links.
My style for the items are as follows
<Style x:Key="LinkStyle" TargetType="{x:Type Hyperlink}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
开发者_如何学运维 <Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
<Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
<Setter Property="Foreground" Value="#FFDDDDDD"/>
<Setter Property="Cursor" Value="Arrow" />
</Style>
Why?
No need to wonder - use XPerf and find out. The video on the topic given at PDC09 is excellent, you'll be up and running quickly.
I have had a similar issue with styles in my application. With out seeing the whole xaml file of the UI, I would ask if you are using any Bitmap Effects, as these will cause issues with the CPU performance going up. If you are, I recommend not using them and instead used the optimized effect options or use the shader library support in WPF to apply any effects you are looking for.
With my example I had an Element with a drop shadow bitmap effect and was able to switch it to the drop shadow effect, got the desired effect and CPU was not hit. When I had the bitmap effect, it was actually redrawing the whole rectangle region that the effect was on, so when I had a blinking cursor it would redraw every child control from the parent that had the Bitmap effect applied in it.
If you are not using any effects, than I recommend looking at your visual tree and see if it is heavy with UI elements or finally and sometimes the most over looked, check your triggers and/or events that you may have defined for the over state of the Hyperlink type that is being displayed could be something hanging out there that is causing some issues.
Hyperlink is your own type, right?
I tried applying your style to a TextBlock instead and could not get CPU to go over 5%, so maybe something is going on inside Hyperlink when one of these properties change. Try to isolate which property is causing the CPU to spike.
精彩评论