I'm trying to get into MVVM from a UWP perspective. Everything seems to work almost like on WPF, but I can't get a good ViewModel/View Mapping running. According to the Microsodt-Specialist: https://channel9.msdn.com/Events/Build/2015/3-635 , starts arround 20 Minutes, there is some new special Syntax for the ResourceDictionaries. I've done all steps, which loads the Dictionary as expected, but the straightforward-mapping doesn't work:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="using:ARGUSnet.RaspberryPiFramework.Designer.Views"
xmlns:vm="using:ARGUSnet.RaspberryPiFramework.Designer.ViewModels"
xmlns:local="using:ARGUSnet.RaspberryPiFramework.Designer.Dictionaries"
x:Class="ARGUSnet.RaspberryPiFramework.Designer.Dictionaries.ViewModelMappingDict">
<DataTemplate x:Key="dtTest" x:DataType="vm:TestViewModel">
<v:TestView />
</DataTemplate>
</ResourceDictionary>
I think the problem herein lies in the fact, I have to define a Key. Although I found some explanations about this, I don't get why this has to be done nowadays. Anyways, the mapping works, if I do this in the ViewContainer directly:
<Page.Resources>
<DataTemplate x:DataType="vm:TestViewModel">
<v:TestView />
</DataTemplate>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ContentControl
Content="{Binding CurrentContent}" />
</Grid>
The problem is, all examples are found are working kinda directly, without an explicit Mapping-Dictionary, or work with Freamworks like mvvmlight. Since this is more for learning purposes, I'd rather make this work without blackboxing the Binding-Mechanics into an Framework.
Is it possible, this is just a Bug in the ResourceDictionary? I also found this Thread, How to associate view with viewmodel or multiple DataTemplates for ViewModel? , but according to my understanding, the question there was about an runtime mapping, while I can bind directly.