I’m using MVVM and each View maps to a ViewModel with a convention. IE
MyApp.Views.MainWindowView
MyApp.ViewModels.MainWindowViewModel
Is there a way to remove the DataTemplate and do it in C#? with some sort of loop?
<DataTemplate DataType="{x:Type vm:MainWindowViewModel}">
<vw:MainWindowView />
</DataTemplate>
So basically, you need to create data templates programmatically… That’s not very straightforward, but I think you can achieve that with the
FrameworkElementFactoryclass :I didn’t test it, so a few adjustments might be necessary… For instance I’m not sure what the type of the resource key should be, since it is usually set implicitly when you set the DataType in XAML