• 提高WPF性能 (2)


    1. Reduce unnecessary invocations of the layout pass -- update a Transform rather than replacing it
    2. Use the most efficient Panel where possible -- don't use Grid if you need is Canvas
    3. Use Drawing which are cheaper than Shape objects
    4. Use StreamGeometry, which is a light-weight alternative to PathGeometry for creating geometric shapes
    5. Use DrawingVisual to render shapes, images, or text
    6. If you need thumbnail images, create a reduced-sized version of the image
      Note: By default, WPF loads your image and decodes it to its full size
    7. Decode the image to desired size and not to the default size
    8. Combine images into a single image, such as a film strip composed of multiple images
    9. Set BitmapScalingMode to LowQuality for smother animating when scaling bitmap to instruct WPF to use speed-optimized algorithm
    10. Set CachingHint when possible, to conserve memory and increase perf
    11. Brush selection is critical to good performance; don’t use a VisualBrush or DrawingBrush when an ImageBrush or SolidColorBrush would be sufficient
    12. To draw complex, static vector content that may need to be repeatedly re-rendered, consider rendering it into a RenderTargetBitmap first and drawing it as an image instead
      Note: Rendering images is usually faster than rendering vector content
    13. Remember to clear event handlers to prevent object from remaining alive (see this post on finding memory leaks
    14. Use Freezable objects when possible to reduce working set and improve perf
    15. Remember to virtualize
    16. Share resources -- if you use custom controls, define control resources at the application or window level or in the default theme for the custom controls
    17. Share a brush w/o copying by defining it as a resource
    18. Use static vs. dynamic resources
    19. Don’t use FlowDocument element when all you need is a Label or TextBlock
    20. Avoid binding to Label.Content property, use TextBlock instead if source is frequently changes.
      Note: String is immutable, so Label object’s ContentPresenter must regenerate new content
    21. Don't convert CLR object to XML if the only purpose is binding
      Note: Binding to XML content is slower than CLR objects
    22. Always prefer binding to an ObservableCollection<T> vs. List<T>
    23. When a brush is used to set the Fill or Stroke of an element, use the brush's Opacity value rather than element's Opacity property
    24. Disable hit testing (IsHitTestVisible = false) when possible
      Note: Hit test on large 3D surfaces is expensive

    更多性能提示请查看MSDN相关文章WPF performance

  • 相关阅读:
    Android四大图片缓存(Imageloader,Picasso,Glide,Fresco)原理、特性对比
    Android系统更改状态栏字体颜色
    Zookeeper使用--命令行
    Zookeeper配置文件
    Zookeeper到底是干嘛的
    shell脚本学习之参数传递
    zabbix3.4.7之Zabbix_Trigger_Function详解
    zabbix3.4.7主动模式监控日志(多关键字)
    linux下grep命令详解
    一些不好理解的名词解释
  • 原文地址:https://www.cnblogs.com/tianhonghui/p/2135929.html
Copyright © 2020-2023  润新知