Separate Views / ViewModels

Topics: Getting Started
May 12, 2011 at 10:36 AM

I've created WP7 application from 1.0 RTW templates and moved MainPage to Views directory and MainPageViewModel to ViewModels directory. I'm unable to start app after this operation.

Console output:

'UI Task' (Managed): Loaded 'C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\mscorlib.dll'
'UI Task' (Managed): Loaded 'System.Windows.RuntimeHost.dll'
'UI Task' (Managed): Loaded 'System.dll'
'UI Task' (Managed): Loaded 'System.Windows.dll'
'UI Task' (Managed): Loaded 'System.Net.dll'
'UI Task' (Managed): Loaded 'System.Core.dll'
'UI Task' (Managed): Loaded 'System.Xml.dll'
'UI Task' (Managed): Loaded '\Applications\Install\AE4BC94D-9675-49CC-94A0-A00122191F0D\Install\CaliburnMicroWindowsPhone1.dll', Symbols loaded.
'UI Task' (Managed): Loaded 'Microsoft.Phone.dll'
'UI Task' (Managed): Loaded 'Microsoft.Phone.Interop.dll'
'UI Task' (Managed): Loaded '\Applications\Install\AE4BC94D-9675-49CC-94A0-A00122191F0D\Install\System.Windows.Interactivity.dll'
'UI Task' (Managed): Loaded '\Applications\Install\AE4BC94D-9675-49CC-94A0-A00122191F0D\Install\Microsoft.Phone.Controls.dll'
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Phone.dll
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Phone.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
The thread '' (0xec20002) has exited with code 0 (0x0).
The thread '' (0x9c000f6) has exited with code 0 (0x0).
The program '[164495666] UI Task: Managed' has exited with code 0 (0x0).

May 12, 2011 at 10:39 AM

Have you tried enabling 'break on exception' in Debug -> Exceptions... -> Common Language Runtime Exceptions -> Throw, to debug the first-chance exceptions?

May 12, 2011 at 10:43 AM

No XAML was found at the location '/MainPage.xaml'.

in 

Microsoft.Phone.dll!System.Windows.Navigation.PageResourceContentLoader.EndLoad(System.IAsyncResult asyncResult = {System.Windows.Navigation.PageResourceContentLoader.PageResourceContentLoaderAsyncResult}) + 0x2f bytes


May 12, 2011 at 10:49 AM

It seems that your application is searching the main page in the wrong place.

I have never developed for WP7, so I don't know what you should do to fix this (is there a project setting to specifiy the startup page?), but I suppose you could search for all entriers in your files (project included) for /MainPage.xaml and change it to /Views/MainPage.xaml.

It seems to me that you did not inform your project that the main page has to be retrieved from another place.

May 12, 2011 at 10:51 AM

There's something like urimapper, i'll try with that.

 

<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
May 12, 2011 at 11:26 AM

Look at this

http://www.windowsphonegeek.com/articles/All-about-UriMapping-in-WP7

May 12, 2011 at 11:48 AM
Edited May 12, 2011 at 11:49 AM

You can also change the Properties/WMAppManifest.xml file in order to reflect the new start page position (it is started by the WP7 runtime):

 

<?xml version="1.0" encoding="utf-8"?>

<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
  <App ...>
    ...
    <Tasks>
      <DefaultTask  Name ="_default" NavigationPage="Views/MainPage.xaml"/>
    </Tasks>
May 12, 2011 at 11:49 AM

That's right EOD ;)