简体   繁体   中英

wpf c# can't open window

I've created a new window in wpf named AfterLogin. I'm trying to open it with button like

VMR_Launcher.AfterLogin af = new VMR_Launcher.AfterLogin();
af.Show();

and like that

AfterLogin af = new AfterLogin();
af.Show();

It throws error Cannot locate resource AfterLogin.xaml

I have other windows too, but they working with those commands, and this afterlogin not. idk why. Every new window doesn't work too.

What I would do, which has solved these types of one off things for me in the past, is create a new window in the folder its going to be in and start to copy the code over. Try copying just some of the code and functionality and build up to all of the code. If you finish copying over forget about ever having a problem and dismiss it as a one off. Its hard for us programmers to give up on figuring out why a problem occurs, but sometimes its better to just solve it the easy way and move on.

Try doing this.


AfterLogin af = new AfterLogin();
af.ShowDialog();

Make sure that AfterLogin.xaml file is there in your project. If it is not then import it.

If it is already there, then there must be one App.xaml file inyour project.

Open it! Inside <Application> tag,there will be <Application.Resources> tag, inside this tag make sure that code similar following exists.

<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="AfterLogin.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

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