问题
I'm performance profiling a WPF application written using the PRISM library. Navigating from one view to another view is particulary slow in this application, especially when navigating away from a "heavy" view. Note that:
- views are cached and not re-constructed when navigating back & forth
(a consequence of PRISM keeping all views in the SingleActiveRegion) - I understand that constructing a view can be slow the first time due to xaml parsing, JIT'ing, .. BUT this question is about navigation remaining slow, even AFTER opening a view for the first time
Using the PRISM library, regions are generally implemented on a ContentControl, like:
<ContentControl regions:RegionManager.RegionName="MAIN" />
As a consequence, switching a view in the MAIN region will update the "Content" of this ContentControl (as can be seen from the source code). Setting & switching UI elements as the "Content" of a ContentControl has performance side effects (see this blogpost).
To overcome this behavior, I implemented a custom RegionAdapterBase (CachingGridRegionAdapter.cs) for a Grid, which basically adds all views being navigated as Children, and hides all non-active views.
The performance gains are tremendous; navigating from one view to another view is instant now. Question: are there any downsides to this approach?
- memory-wise, I don't see an issue since all views were kept in memory by PRISM anyway
- is there a downside to having a big visual tree, with many parts having Visibility = Collapsed?
If there are any other ways to overcome this problem, please let me know.
Thanks for your time,
Koen
来源:https://stackoverflow.com/questions/41937963/prisms-regionmanager-view-switching-performance