zoukankan      html  css  js  c++  java
  • 提高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

  • 相关阅读:
    八爪鱼 爬取微博中的图片到本地
    【简易采集】美团数据抓取方法 八爪鱼
    jeesite 的提示消息图标
    SpringBoot 入门 Demo
    spring 简单入门实例
    正则表达式之匹配替换
    数据结构之堆栈
    c#设计模式之装饰者模式
    c#设计模式之策略模式
    一个自然数在1700和1800之间,且被5除余3,被7除余4,被11除余6,求符合条件的数
  • 原文地址:https://www.cnblogs.com/tianhonghui/p/2135929.html
Copyright © 2011-2022 走看看