There are multiple places in my application whehe I have ContentControl
placed in xaml and I do not know beforehand what its Content
is going to be. What is the best practice to implement this scenario?
Right now I am considering two approaches:
- Bind
ContentControl.Content
to view model and use a dictionary ofDataTemplate
s to find an appropriate view. My issue with this approach is that even if I were to list all the possible combinations in a dicitonary, in some cases I simply do not know an exact type of view (or viewmodel if there is any) at compilation time. I think, I am also going to have troubles using this approach for hosting non-WPF content. Create some sort of an interface:
interface IContentPlugin : IDisposable { object View { get; } }
and bind
ContentControl.Content
toIContentPlugin.View
directly. I could then have multiple implementations of this interface and swap them when I need to. But this solution does not strike me as something that goes well with MVVM application, as it forces me to have references toIContentPlugin
s in my view models.
What do you think is the best option and why? Perhaps there is a better approach?