I am making an application, but silly me I made the main application in the Main Window, but I need to make an opening screen with a start button which opens the main application, any help?
Related
I am developing a UWP app with multiple views. (Say I open my app's settings in a separate window.) I need to recover my app's main view in the following scenario.
Open the app.
Open app settings in a secondary view.
Close the main view of the app and leave the settings window open.
Open the app from start menu or by clicking on the app's shortcut icon.
The above action takes me to the already opened secondary view(settings window). But I need to bring up the main view of the app.
In my App.xaml.cs file, OnLaunched method, CoreApplication.GetCurrentView().IsMain gives me true but CoreApplication.GetCurrentView().IsHosted gives me false. I tried with CoreApplication.GetCurrentView().CoreWindow.Activate() & Window.Current.Activate(); but both didn't help, it just takes me to the secondary view(settings window) which is left open.
How to bring up the main view of my UWP app?
For your requirement, you could refer MultipleViews official code sample. And it has switch to main view action. you could use it to switch to main view event if the main view closed.
private async void GoToMain_Click(object sender, RoutedEventArgs e)
{
// Switch to the main view without explicitly requesting
// that this view be hidden
thisViewControl.StartViewInUse();
await ApplicationViewSwitcher.SwitchAsync(mainViewId);
thisViewControl.StopViewInUse();
}
I found the solution to my problem. My requirement was, when the app's main window has been closed, but a secondary window is still open, and the user tries to open the app from the start menu or by clicking the app's icon, I should bring up the main view of the app in a separate window, without closing the secondary view/window where the user currently is. In other words, just bring the main window of the app in front and let the secondary window be there as it is behind the main window. So now we will have 2 windows on screen:
1.Main window
2.Already opened secondary window.
I achieved this by the below code.
In the App.xaml.cs file, OnLaunched(LaunchActivatedEventArgs e) method, the argument LaunchActivatedEventArgs e has a property named CurrentlyShownApplicationViewId, which gives the id of the view, where the user currently is (if any of the app view is open).
ApplicationView.GetApplicationViewIdForWindow(CoreApplication.GetCurrentView().CoreWindow) gives the id of the main view of the app.
With these 2 id's in hand, I am able to bring up my app's main window, with the help of the below code.
Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
ApplicationView.GetApplicationViewIdForWindow(
CoreApplication.GetCurrentView().CoreWindow),
ViewSizePreference.Default, e.CurrentlyShownApplicationViewId,
ViewSizePreference.Default);
});
ApplicationViewSwitcher.TryShowAsStandaloneAsync brings back my app's main window in front, in a separate window, leaving behind the secondary window undisturbed. So now the user has 2 windows - the app's main window as well as the existing secondary window.
I am making a game that has a main home screen (that is a windows form) and i need some code that will just close the xna window but not the form.
I've looked everywhere but can't seem to find an answer. I figured out how to open the form, I just need to close the opened xna window so just my main menu is there and i can start another xna game.
There is an answer to your question here. Essentially, you will need to modify the opacity to hide the game window. The game will still be active.
Edit
my game continues to run in the backgound and so on my main menu i can't start another instance of that game
If you need to completely close the XNA game, the game will need to be launched from the Windows Form application. In your Windows Form application you can use:
Game1 myGame = new Game1();
myGame.Run();
to run the XNA game. Then when you use Game.Exit() (in the XNA application) to close the game, the main menu should still be open in the background.
I am altering an existing windows compact framework application and i did most of the part and i noticed the different behavior of the form.
Consider i am Opening my application, "ApplicationForm" is the main form and on clicking Next button in ApplicationForm another form say "NextForm" will open.I am using below code to open the NextForm.
NextForm obj = new NextForm();
obj.Showdialog();
Now NextForm screen is in open and at this time if I open FileExplorer in device,FileExplorer will open.Now if i Open my installed application from device from Start menu,the application opens with the last open Form say NextForm.It will show NextForm in screen but from here if i click Back button in NextForm it is taking me to FileExplorer.Actually it should take me to ApplicationForm and it works fine when FileExplorer is not opened.
1.I need to navigate to ApplicationForm if i click Back button in NextForm even if FileExplorer is opened in the above scenario.
2.Is it possible to set like this,even the application is opened and the user is in any say NextForm form,when user click application from Start menu it should open the ApplicationForm(which is the Main form) and all other form(NextForm) should close automatically.
Is it possible to solve this issue.
I have tried two installers - Setup2go, and Installmate Builder, and I have the same problem. At the last window of the install, I select the option to "Open program after installation finish", and sometimes (about 10% of the time?), my (Winforms) app's main window will open behind the Windows Explorer directory window I used to open the installation exe from.
The frustrating thing is - I am having trouble reproducing the problem reliably (the problem seems to occur around 10-20% of the time). I am using Windows 7 if that makes any difference. To clarify, if I open up the executable directly (rather than from the installation exe), the problem never occurs.
My knowledge on this kind of thing is limited - I recall a similar frustration happening with the MessageBox from this question
Any ideas?
It does not happen when you launch the app directly from installer because the shell allows it to “steal” the focus. When you launch it from the installer, the last interaction happens in the installer app. The system prevents the new window from stealing the focus from your installer. If installer window closes, then the explorer window which you used to start the installer is activated. Since the switch of the foreground window happened recently, the system does not allow to change the foreground window.
On the other hand, if your application window is shown before the installer window disappears from the screen, the the app will be placed below the installer in the Z-order; and when the installer window is finally hidden, the application window is activated.
So it's all related to timing between showing and hiding windows.
Although I am not expert in this area. You can use message tracers and WinAPI calls tracers like Spyxx which can give you more details on what happens in the system and why the new window of your application is placed below the Explorer window.
Make sure the window's title isn't changed, until the last possible moment. I moved the Text = "blahblah" line out of the Form_load event, and into the Form1_Shown event, and now the hidden taskbar icon problem has vanished. Also, the window doesn't flicker when it's loading.
Goal:
Enable closing of the application's window(s) independently without affecting others. The application is created in WPF.
Problem:
Can't close the window(s)
In winform, it is enough to have the code winform.close() to close down the window but it doesn't work in WPF.
You can have this code to close a specfic window:
Application.Current.Windows[0].Close();
but how would it work if you have many windows and you want to close a specific window without affecting the others?
Use the Application class to get the windows through Application.Windows-property exactly as you described. If you are in the code-behind of the window, call this.Close();
Configuration for multiple Windows
Set the main window to the Application.MainWindow property and set the Application.ShutdownMode to a appropriate value if you also want to hold the app open, if the main window is closed (e.g App.Current.ShutdownMode=ShutdownMode.OnExplicitShutdown; ).
I have already observed, that some people have had problems with the ShutdownMode. A workaround for this is to open the first window invisible and from this window, you open the visible application windows. This prevents the application from closing if the first created window will be closed. However you should be able to resolve this problem also over the ShutdownMode-property.
In scenarios with multiple windows, you can use Shutdown to close the app without closing every window.
I hope this answer is what your question is about. Make a comment if not.
I am agree with HCL. You can use this.Close(); from code-behind of the window, this will close WPF window as like winform.close();.
Or you can use following code for get the specific window for close
Window win = Application.Current.Windows.OfType<Window>().SingleOrDefault(w => w.Name == "Window Name");
win.Close();
just use this code to close the most recent window
Application.Current.Windows[Application.Current.Windows.Count - 1].Close();