Windows-XAML / Template10

Making Windows 10 apps great again
Apache License 2.0
1.41k stars 389 forks source link

Navigation, History, etc, without using INavigable #1060

Closed selaromdotnet closed 8 years ago

selaromdotnet commented 8 years ago

I love template 10 and want to be able to leverage the navigation service to create a UWP version of an app I've written for Universal 8.1 and Xamarin Forms. However, this app was written with MvvmLight, with the Viewmodels in the PCL, shared to both the Windows 8.1 and Xamarin platforms.

As a result, I cannot inherit from INavigable in my PCL project to get the automatic navigation that calls the OnNavigatedTo, OnNavigatedFrom, etc., from the View in the UWP UI project passing to the ViewModels as you would do if everything was in the win10 project.

So far, the only way I've been able to achieve some success is by inheriting from my core PCL viewmodels in my UWP UI project and adding the INaviable interface to these, and passing the INaviable methods to the corresponding base viewmodel methods to activate them and pass parameters on navigate (as well as save them on navigate away).

this works (pretty well actually, I even kept my design time support from the pcl viewmodels) but it's a bit cumbersome and wordy.

Ideally (well for me of course, not template 10) the INavigable interface would be in a PCL so that I could just add it to my core project and be done with it.

Since this is obviously not possible (given dependencies on Win10 for Dispatcher, navigationmode, etc used by the navigation service), am I on the right/only track to make this work by using inheritance to decorate my viewmodels with the INavigable interface in the UI project?

the only other way I can think of getting the same kind of result is ditching template 10's navigation service entirely and copying over the suspension manager from Win8.1 to handle the navigation, back stack, etc. this works (I blogged about how to do that here), but I much prefer to use template 10 than recycling bits from my 8.1 project...

This is likely a case of that 20% of projects that just don't fit template 10, but I sure hate to lose all the work I did making my original project cross platform only to discover I locked myself out of using template 10 as a result.

I'd appreciate any insight or advice on how I might best achieve this, or if I am indeed on the right/only track for doing this, that'd be good to know too. thanks!

selaromdotnet commented 8 years ago

I just realized after submitting this isn't really an "issue" to be logged (other than to perhaps suggest the INavigable be portable, which is probably not possible), so if this would be better posted on StackOverflow please let me know and I'll direct such questions there in the future. thanks agian

JerryNixon commented 8 years ago

We'll move all the interfaces in Template 10 to a cross-platform PCL when we release the Anniversary Update version of the library. That is the current plan. I can't solve your problem now, but that update should come pretty soon. We will not build it until the Anniversary Update is RTM. That when we start, not when we ship. Remember. Open Source. Volunteers.

By the way, thanks. I know this is important.