- KeldorKatarn
- Posts: 193
- Joined:
DataTemplate performance
Since I'm using DataTemplates for matching ViewModels to Views currently in Caliburn.Noesis, I was wondering how performance heavy it is to re-create datatemplate instances when screens are changes rapidly. Is there some caching going on in Noesis that already deals with the performance impact or should I think about some ways to cache stuff in the framework?
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: DataTemplate performance
Noesis is not caching anything, but it is is fast to apply DataTemplates as long as they are already in memory (in any loaded resource dictionary), because we are just cloning the visual tree of the template.
But it ultimately depends on the complexity of the template. If you plan to load complex screens using data templates maybe it is better to have the main screens already in a root xaml and just switch the visibility of each one accordingly.
But it ultimately depends on the complexity of the template. If you plan to load complex screens using data templates maybe it is better to have the main screens already in a root xaml and just switch the visibility of each one accordingly.
- KeldorKatarn
- Posts: 193
- Joined:
Re: DataTemplate performance
I found a good solution :) I'm mixing Caliburn.Micro's approach with mine. I still generate DataTemplates for each ViewModel, but they no longer contain the entire view UserControl.
Instead they have a ContentPresenter with an attachedProperty which connects to the ServiceProvider to resolve the view. The serviceLocator is injected into the DataTemplate as a resource.
Instead they have a ContentPresenter with an attachedProperty which connects to the ServiceProvider to resolve the view. The serviceLocator is injected into the DataTemplate as a resource.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: DataTemplate performance
And the view is the same object always that gets added/removed to/from the tree?
- KeldorKatarn
- Posts: 193
- Joined:
Re: DataTemplate performance
Yes. I also added something in case the view is used in multiple places against the same viewmodel. The framework now automatically adds an attached property containing a location ID to the parent Visual so the framework caches them in the viewmodel by location. but yes the UserControl always gets injected into a new contentpresenter wherever the datatemplate is instantiated. So the only thing Noesis needs to re-instantiate for the datatemplate is only the ContentPresenter control, nothing else. Everything below it gets injected by the framework as either a IoC lookup or a cached instance. Works great :)
Who is online
Users browsing this forum: Semrush [Bot] and 9 guests