Search code examples
c#xamlwindows-store

Move and rename MainPage.xaml


I am developing a Windows Store project, and I wish to move MainPage.xaml into a folder called Views. After that I want to rename it. I already attempted doing this, but I ended up breaking it (InitializeComponent could not find a definition).

How can I move and rename the page properly?


Solution

  • Actually, it seems that the MainPage type is hard-coded in the auto-generated code.

    look at this post to get information on how to change it.

    Let's say you renamed it to MyView.xaml, and moved it to Views folder.

    You will probably want (not necessary) to also:

    1. add ".Views" to the namespace in MyView.xaml.cs
    2. add ".Views." to the x:Class tag in MyView.xaml
    

    Now open App.cs, and locate the following line

    if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
    {
         ....
    }
    

    change MainPage to reference your new page name.