Moving MainWindow.xaml
I just ran into this myself. Here's what I did:
- Move your
MainWindow.xaml
to your new folder. In my case it was /Views. - I like to name all my classes with their namespaces reflecting their folder. So my
MainWindow.xaml.cs
namespace went fromProjectNamespace
toProjectNamespace.Views
- In my
MainWindow.xaml
, I needed to changex:Class
fromProjectName.MainWindow
toProjectName.Views.MainWindow
. - In your App.xaml, change the
StartupUri
to reflect the folder. I went fromStartupUri="MainWindow.xaml"
to "StartupUri="Views/MainWindow.xaml"`
Doing this allowed me to compile and run my app.
The answer of @Rohit Vats is quite good!
However there's a good point to remember: you have to change all the absolute paths (in XAML) to your resources, prepending them by a /
in order to indicate that these paths are relative to the root directory
.
Example:
From <Image Source="Assets/Loading.gif">
To <Image Source="/Assets/Loading.gif">
and so on.
You don't need to update class name in xaml file unless you have changed the namespace of your class.
Most likely you haven't updated StartupUri
for App.xaml
. Change it to:
StartupUri="view/MainWindow.xaml"
from
StartupUri="MainWindow.xaml"