Should I declare converters in App.xaml or as a per-file resource?

前端 未结 3 1219
逝去的感伤
逝去的感伤 2020-12-14 03:28

When declaring converters in a WPF application, should I:

  1. Declare all my converters in the App.xaml (i.e. in
3条回答
  •  萌比男神i
    2020-12-14 03:52

    I have a ResourceDictionary that declares several commonly needed converters, such as a bool-to-visibility converter. I reference this dictionary directly in App.xaml.

    I declare other converters that are more specific to a given situation at the Page/Window-level (or in a ResourceDictionary referenced by a Page/Window).

    I can't answer the performance question definitively, but I would be very surprised if it made a practical difference in load time or memory usage. Declaring a converter is basically an object instantiation, so it should be very efficient and use very little memory, but I haven't done any profiling to compare app-level vs. window-level performance.

提交回复
热议问题