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

  • 相关阅读:
    类的嵌套
    一种设计模式--单例模式
    python中的类(二)
    Python中的类(一)
    基于session和cookie的登录验证(CBV模式)
    Django中的CBV和FBV
    python3 装饰器
    cookie和session
    基于cookie和session的登录验证
    python3 安装win32api
  • 原文地址:https://www.cnblogs.com/tianhonghui/p/2135929.html
Copyright © 2011-2022 走看看