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.Contentto view model and use a dictionary ofDataTemplates 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.ContenttoIContentPlugin.Viewdirectly. 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 toIContentPlugins in my view models.
What do you think is the best option and why? Perhaps there is a better approach?