Reputation: 902
How can I change the location of the default MainPage.xaml
in an Universal Windows App
? I want to have in the Windows and WindowsPhone Project a subfolder named "View" where I save the MainPage.xaml
file like this example.
- Windows Project
-- View
--- MainPage.xaml
- WindowsPhone Project
-- View
--- MainPagePhone.xaml
- Shared Files
-- Model
-- ViewModel
-- App.xaml
With that structure I have a problem in the App.xaml.cs
that the MainPage
can't be find.
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
Upvotes: 0
Views: 226
Reputation: 117
If you want to have different names (mainWinPage / mainPhonePage ) you have to tell him which one to take, every time you use it in Shared-Project:
#include yournamespace.Views;
..
#if WINDOWS_APP
if (!rootFrame.Navigate(typeof(MainWinPage), e.Arguments))
...
#else // or #if WINDOWS_PHONE_APP
if (!rootFrame.Navigate(typeof(MainPhonePage), e.Arguments))
...
#endif
or just use same names, makes it easier.
Upvotes: 0
Reputation: 592
First, you don't need to give different names to your files, use MainPage for both phone and pc project and put MainPage.xaml inside the view folder. The Universal App will be aware of which platforms it runs on and it will load the right page accordingly. You need to create the view folder and the MainPage.xaml file in both projects. Delete every MainPage.xaml files outside of the View folder.
Then navigate to your App.xaml.cs shared file.
Look into the onLaunched
method, you should find something like this at the end of the method:
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
This is where your project try to load the page. MainPage should be marked as an error because we're missing the reference.
So, add this at the top of the App.xaml.cs page:
using NameOfYourProjectHere.View;
Let me know if it works!
Upvotes: 2