The way I do it in several commercial projects is as follows:
I have a standard IValueConverter
public class ViewTemplateChooser : IValueConverter {
Converter will require namespace registration
xmlns:Converters="clr-namespace:YourProject.Converters"
Then you refer to the converter in the resources section:
<UserControl.Resources> <Converters:ViewTemplateChooser x:Key="TemplateChooser" /> </UserControl.Resources>
and finally, I use the converter to convert the ViewModel into a view with the Datacontext of the view set in the ViewModel
<ContentControl Content="{Binding Workspace, Converter={StaticResource TemplateChooser}}" Margin="5,35,5,5" Grid.Column="1" />
The converter can be modified to implement navigation strategies, I tried to make the example as simple as possible.
Hope this helps, you donβt need to go to extremes - or third-party libraries - to get what you are looking for.
Ronnie barnard
source share