Can the latest release of Prism for Windows Runtime be used in a Windows 10 preview solution?

Apr 1, 2015 at 3:42 PM
Edited Apr 1, 2015 at 3:43 PM
I wonder if the latest release of Prism for Windows RT can be used to implement a MVVM pattern in a solution with the Windows 10 preview (and Visual Studio 2015 CPT).
What about Unity?
Apr 2, 2015 at 2:37 AM
Edited Apr 2, 2015 at 2:38 AM
Hey,

I tried. So far so good with Windows 10, but it crashes in the phone emulator:
TypeLoadException: Requested Windows Runtime type 'Windows.UI.ApplicationSettings.SettingsPane' is not registered.

I noticed this in the MvvmAppBase class:
#if WINDOWS_APP
                SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
#endif

#if WINDOWS_PHONE_APP
                HardwareButtons.BackPressed += OnHardwareButtonsBackPressed;
#endif
I haven´t figured out how to handle this... Anyone have any ideas?

Thanks,

René
Apr 2, 2015 at 1:09 PM
Edited Apr 2, 2015 at 1:45 PM
Thank you Renè for your reply and for sharing your experience!
So, if I took it right, you tried with success to use Prism for the Windows Runtime for a Visual Studio 2015 CPT Universal App solution in a Windows 10 preview PC.
In particular you succeded make it compile but at runtime it worked for Windows target but not with the VS2015 WP emulator. Did you tried to deploy on a WP device with installed the "Windows 10 for phone" preview [http://windows.microsoft.com/en-us/windows/preview-download-phone]?
Which version of Prism did you test? I see that in the repository [https://prismwindowsruntime.codeplex.com/SourceControl/latest] There is not only a 8.1 version but also a "Converged " one ...
Did you use a Universal App template with a single project [for both WIN and WP] or with two different projects (one for WIN and the other for WP) + shared project, so you had to make a reference to PRISM in both as it used to be in Windows 8.1 Universal App solutions?

PS: looking to the error you received, I suppose that you are using a single project with the target WINDOWS_APP, so when running in WP, that has not the SettingPane, that line of code (SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;) causes the error. So I am wondering if it is possible to use PRISM using a single project or if there is still the need, as it was for 8.1 Universal Apps, to have two different project (one tageted WINDOWS_APP and the other WINDOWS_PHONE_APP) and use the shared project for possibly having common XAMLs. I suppose that in WINDOWS 10 it will be generated (even There are different taget projects) a single binary because the Store will be one (anyway I wonder in which directory it could be found after a VS2015 compiling ...)!

Let me know ;-)
Enzo
Apr 2, 2015 at 11:41 PM
Edited Apr 2, 2015 at 11:43 PM
Hi Enzo,

Yes, I have Windows 10 preview installed on a box with Visual Studio 2015 CTP 6 along with the Windows 10 Technical Preview tools. I'm also using the new Universal App -> Everything in one project.

The first thing I tried is installing all the relevant Prism Nugets. It compiles without any problem. It however install the Windows 8.1 stuff, meaning you end up with this guy referenced: Microsoft.Practices.Prism.StoreApps.Windows.

That means this is enabled:
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
That works just fine (although the Settings pane seems to be gone in Windows 10). Now when you run it in the Phone emulator, the GetForCurrentView method throws a TypeLoadException.

I tried removing the reference to Microsoft.Practices.Prism.StoreApps.Windows manually, adding the MvvmAppBase file to my project, setting the WINDOWS_PHONE_APP compilation symbol and putting a try catch around the piece that breaks in Windows 10 (not phone) as such:
                try
                {
                    HardwareButtons.BackPressed += OnHardwareButtonsBackPressed;
                }
                catch (TypeLoadException)
                { }
Working so far, but I didn´t try on an actual W10 phone device.

I wanted to use Environment.OSVersion with an if statement, but it's gone. A hack, but hey, when you're on the bleeding edge, you bleed. :)

René
Apr 20, 2015 at 6:01 AM
Hey,

I found the correct way of fixing the MvvmAppBase class:

1- Make sure you reference the Desktop and Mobile extentions.

2- Remove all the #if/#endif statements.

3- Make sure the types exist at runtime:
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ApplicationSettings.SettingsPane"))
{
    SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
}

if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
     HardwareButtons.BackPressed += OnHardwareButtonsBackPressed;
}
Works like a charm. Now I just have to figure out what happened to the SettingsPane...

René
Apr 20, 2015 at 7:36 AM
Thank you René for sharing your experience. Are you going to provide somewhere (ex. as a fork or in a blog) your modified version of Prism that fit for the new Win 10 Universal App? I think your work could be useful not only to some programmers but also to people in charge of Prism evolution ...

Have also a look to the thread https://prismwindowsruntime.codeplex.com/discussions/630692

Regards
Enzo