简体   繁体   中英

StartupUri VisualStudio 2010 not working

I just created a new WPF project, but I decided to make a different organization of the folders, to make them look like this:

在此处输入图片说明

So I want all my interfaces to be on src folder. But when I press F5 and try to run it, the debugger says it can't find MainWindow.xaml . The xaml look like this:

App.xaml

<Application x:Class="MyNamespace.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>

MainWindow.xaml

<Window x:Class="MyNamespace.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>

</Grid>

Apparently they share the same namespace, but it's not finding the MainWindow.xaml ... Any idea why?

App.xaml.cs

namespace MyNamespace.src
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
    }
}

MainWindow.xaml.cs

namespace MyNamespace
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}  

Your MainWindow is in the the "src" folder.

The StartupUri is relative to the structure of your project. So StartupUri = "src\\MainWindow.xaml" should work.

Change the startupuri to "src/MainWindow.xaml", this works for me with an empty project.

Also, in App.xaml.cs, you have namespace MyNamespace.src , this may not be what you intended (doesn't match the others). Sometimes VS automatically appends to the end of your namespaces when you create subfolders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM