Я делаю это в нескольких коммерческих проектах следующим образом:
У меня есть стандартный IValueConverter
public class ViewTemplateChooser : IValueConverter
{
/// <summary>
/// Modifies the source data before passing it to the target for display in the UI.
/// </summary>
/// <returns>
/// The value to be passed to the target dependency property.
/// </returns>
/// <param name="value">The source data being passed to the target.</param><param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param><param name="parameter">An optional parameter to be used in the converter logic.</param><param name="culture">The culture of the conversion.</param>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is MyViewModel)
{
return new MyView { DataContext = value };
}
return value;
}
/// <summary>
/// Modifies the target data before passing it to the source object. This method is called only in <see cref="F:System.Windows.Data.BindingMode.TwoWay"/> bindings.
/// </summary>
/// <returns>
/// The value to be passed to the source object.
/// </returns>
/// <param name="value">The target data being passed to the source.</param><param name="targetType">The <see cref="T:System.Type"/> of data expected by the source object.</param><param name="parameter">An optional parameter to be used in the converter logic.</param><param name="culture">The culture of the conversion.</param>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Для преобразователя потребуется регистрация пространства имен
xmlns:Converters="clr-namespace:YourProject.Converters"
Затем вы ссылаетесь на конвертер в разделе ресурсов:
<UserControl.Resources>
<Converters:ViewTemplateChooser x:Key="TemplateChooser" />
</UserControl.Resources>
и, наконец, я использую конвертер для преобразования ViewModel в View с Datacontext для представления, установленного в ViewModel
<ContentControl Content="{Binding Workspace, Converter={StaticResource TemplateChooser}}" Margin="5,35,5,5" Grid.Column="1" />
Конвертер можно модифицировать для реализации стратегий навигации, я постарался максимально упростить пример.
Надеюсь, это поможет, вам не нужно идти на крайние меры - или на стороннихбиблиотеки - чтобы получить то, что вы ищете.