I haven't really found my answer to my problem anywhere, so I really hope that someone actually was solving similar problem before me.
I'm developing an UWP application after I was messing with MVVM stuff in WPF for like a year (no widespread frameworks/libraries, just very basic stuff to get the grasp of it). I've come to the realization that I can't really recreate my beloved patterns in UWP, because it has tighter rules than WPF.
What I did in WPF: What I had was few VMs with INPC and properties, etc. and Views with bindings, usual stuff. It was coupled together by the magic of DataTemplate and a really simple method:
public static void Show(this ViewModelBase vm)
{
CreateWindow(vm).Show();
}
private static Window CreateWindow(ViewModelBase vm)
{
return new Window
{
Icon = Resources.app_icon.ToImageSource(),
Width = 500d,
Height = 320d,
Content = vm,
Title = vm.ToString()
};
}
In my ResourceDictionary, I defined all templates for my ViewModel classes, like so:
<DataTemplate DataType="{x:Type local:RandomViewModel}">
<local:RandomView />
</DataTemplate>
UWP situation: I started with a ViewModels that derived from ContentControl, which worked as a prototype, but was ugly and severely broke MVVM "rules" (imho). I switched to the DataTemplate ResourceDictionary with underlying static class that I saw on Build (2016?) conference, which led me to my current state. DataTemplate now has to have a x:Key, which prevents me to leave everything so loosely coupled. Of course the DataTemplate works if I explicitly use the key for ContentTemplate, but that's something I wanted to avoid.
After few weeks of thinking and contemplating and being all frustrated with it, I finally decided to ask someone to at least give me a hint of how to deal with this. For this specific application, I don't really want to go down the road of "do-everything" framework. I also wanted to use compiled binding, so the whole Content/DataContext business is gone also.
Is there a elegant (and simple) or obvious solution that I've missed? I'd be really thankful for any useful tips.
Edit: I know that the question is very vague, If I knew exactly what to ask for, I'd probably keep searching the internet / trying to figure things out by myself. I hope you don't mind.
View Locator
and/orViewModel Locator
, here's a good post that might get you going Navigation Between Pages Using MVVM Light in Universal Windows Platform(UWP) – Hydromagnetics