Unable to cast object of type 'App.Views.MainPage' to type 'Microsoft.Practices.Prism.Mvvm.IView

Oct 21, 2014 at 5:49 PM
I have integrated Prism for Windows Runtime in my Windows 8.1 app. I have the latest prism installed. In the OnLaunchApplicationAsync in app.xaml,cs, I am navigating to my experience which is "Main".
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
    this.NavigationService.Navigate("Main", null);
    return Task.FromResult<object>(null);
}
Here when I run the project, I am only getting a blank screen and IntelliTrace shows me "Unable to cast object of type 'App.Views.MainPage' to type 'Microsoft.Practices.Prism.Mvvm.IView". I have abstract partial class PageBase which inherits from Page and implements IView. My MainPage is implementing PageBase as well.

Design time data is displayed, but not in the runtime. OnNavigatedTo method in my runtime MainPageViewModel, is not getting hit.

I have also ViewModelLocator.AutoWireViewModel="True" in the MainPage.xaml. MainPageViewModel is inheriting ViewModel and implementing IMainPageViewModel. App.xaml.cs is inheriting MvvmAppBase. Everything seems to be perfect. But it is not working.

Any ideas. Appreciate any help.

Thanks.
Oct 22, 2014 at 6:18 AM
I have managed to solve the problem by making the following changes.
  1. MainPage is now inheriting from VisualStateAwarePage and no longer implements PageBase which inherits from Page and implements IView.
  2. MainPage.xaml is now based on VisualStateAwarePage and no longer from PageBase.
Though it is working, I still need to know why it is not working with the PageBase. VisualStateAwarePage is also inheriting from Page and implementing IView. So why my PageBase is not working. It's weird and strange.

Appreciate your all ideas.

Thanks.