Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My WPF Application cannot locate resource 'Mainwindow.xaml'

Tags:

vb.net

wpf

xaml

I have been working on a WPF application using vb.net and I've recently run into a problem.

When I build my code, the build is successful but when it comes to running the code the System.IO.IOexception throws an exception "Cannot locate resource ViewModel/ViewModel/Mainwindow.xaml" The .Xaml windows are located in a folder called ViewModel hence I don't know where the other ViewModel/ViewModel... path is coming from, isn't it supposed to be viewModel/MainWindow.Xaml? I have tried all possible solutions including cleaning up the Project but it doesn't seem to work.

The only solution that seems to work is if I change the StartupUri from StartupUri = "ViewModel\MainWindow.Xaml" TO StartupUri = "...\MainWindow.xaml" but I doubt if that is the right thing to do.

like image 550
George Avatar asked Mar 21 '13 09:03

George


4 Answers

Change the StartupUri="MainWindow.xaml" to StartupUri="FolderName/MainWindow.xaml"

Solved my problem, when I moved my MainWindow to the View Folder

like image 98
Arijit Mukherjee Avatar answered Nov 12 '22 05:11

Arijit Mukherjee


In my case I needed to use pack URI syntax to set SrartUpUri property of my App.xaml file to point to a new location of my MainWindow.xaml, as so:

   <Application x:Class="TrafficLights.Controller.App"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                StartupUri="pack://application:,,,/View/MainWindow.xaml">

More on pack URIs here:

http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx

Hope it helps. Good luck!

like image 39
Alex Krotnyi Avatar answered Nov 12 '22 05:11

Alex Krotnyi


This happened to me few times - always when I moved MainWindow.xaml to different folder and forgot to update StartupUri in App.xaml.

like image 8
Libor Avatar answered Nov 12 '22 07:11

Libor


Visual Studio has somehow renamed my MainWindow.xaml to MainWindow(1).xaml, so again I renamed it to MainWindow.xaml

like image 1
jclstefan Avatar answered Nov 12 '22 05:11

jclstefan